我试图创建一个自定义标记云小部件,该小部件如下所示:
此外,当我尝试在帖子中添加一些新标签时,它会显示如下内容(只有一个标签):
这是我的functions.php
if(function_exists(\'register_sidebar\')) {
register_sidebar(
array(
\'name\' => __(\'Main Sidebar\'),
\'id\' => \'main-sidebar\',
\'description\' => __(\'The main sidebar area\'),
\'before_widget\' => \'<div class="widget">\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<h2>\',
\'after_title\' => \'</h2>\'
));
}
/****************************************************/
/* Load Custom Widgets */
/***************************************************/
require_once(\'functions/rh_tags.php\');
这是我的rh_tags.php
<?php
class RH_Tags extends WP_Widget {
function __construct() {
$params = array(
\'name\' => \'Creative : Tag Cloud Widget\',
\'description\' => \'Displays info of your blog\'
);
parent:: __construct(\'RH_Tags\',\'\',$params);
}
public function form($instance) {
//display our form in widget page
extract($instance);
?>
<p>
<label for="<?php echo $this->get_field_id(\'title\') ?>">Title : </label>
<input class="widefat" id="<?php echo $this->get_field_id(\'title\') ?>" name="<?php echo $this->get_field_name(\'title\') ?>"
value="<?php if(isset($title)) echo esc_attr($title); ?>" />
</p>
<?php
}
public function widget($args,$instance) {
//displays our widget
extract($args);
extract($instance);
echo $before_widget;
echo $before_title .$title. $after_title;
echo \'<div class="label">\';
echo "<ul>";
echo "<li>";
echo the_tags(\' \',\' \');
echo "</li>";
echo "</ul>";
echo \'</div>\';
echo $after_widget;
}
}
add_action(\'widgets_init\',\'rh_register_tags\');
function rh_register_tags() {
register_widget(\'RH_Tags\');
}