我通过简单地复制一个默认的widgets类并修改它来创建widget
奇怪的是,小部件管理区域中没有显示此小部件。当我搜索页面源代码时,小部件在那里,但它有内联样式display:none;
.<另一件奇怪的事是,标题字段也没有显示
这是我的小部件代码:
/**
* Mood widget class
*
**/
class WP_Widget_Mood extends WP_Widget {
function __construct() {
$widget_ops = array(\'classname\' => \'widget_mood\', \'description\' => __( "Mood widget") );
parent::__construct(\'mood\', __(\'Mood\'), $widget_ops);
}
function widget($args, $instance){
extract($args);
$title = apply_filters(\'widget_title\', empty($instance[\'title\']) ? \'Mood\' : $instance[\'title\'], $instance, $this->id_base );
$user_id = get_current_user_id();
$table_name = $wpdb->prefix . "mood";
$get_same=$wpdb->get_row("SELECT * FROM $table_name where user_id=\'".$user_id."\' order by id desc");
$get_mood_row = mysql_query("select * from wp_mood where user_id=\'".$user_id."\' and mood=\'".$get_same->mood."\'");
$pathredirect = get_bloginfo(\'url\').\'/m/\'.$current_user->user_nicename.\'/settings/mood/\';
global $current_user;
$current_user = wp_get_current_user();
?>
<h3 class="sideheading"><?php echo $title; ?></h3>
<dl id="settingss" class="dropdown3">
<dt>
<a title="Options" href="#setting">
<div id="rightsetting" class="sprite"></div>
</a>
</dt>
<dd>
<ul>
<li><p id="wlcmstg2" class="sprite"></p><a href="#Make">Make</a></li>
<li><p id="wlcmstg1" class="sprite"></p><a href="<?php echo $pathredirect;?>">Setting</a></li>
</ul>
</dd>
</dl>
<div id="charectersbar">
<div id="prev"><span id="go-prev2" class="sprite"> </span></div><!--#prev-->
<div id="slide">
<div id="slider2">
<?php
//echo "select * from wp_mood where user_id!=\'".$user_id."\' and mood=\'".$get_same->mood."\'";
$res_mood = mysql_query("select * from wp_mood where user_id=\'".$user_id."\' and mood=\'".$get_same->mood."\'");
$ii=0;
while($result_mood = mysql_fetch_array($res_mood)){
$ii++;
$uuserid = $result_mood[\'user_id\'];
$user_info = get_userdata($uuserid);
?>
<div>
<a href="<?php echo bloginfo(\'url\');?>/m/<?php echo $current_user->user_nicename; ?>/profile">
<img title="<?php echo $result_mood[\'nikename\'];?>" src="<?php echo bloginfo(\'url\').\'/wp-content/uploads/mood/\'.$result_mood[\'image\'];?>" /><?php echo $result_mood[\'nikename\'];?>
</a>
</div>
<?php } ?>
</div><!--#slider2-->
</div><!--#slide-->
<div id="next">
<span id="go-next2" class="sprite"></span>
</div>
</div><!--#charectersbar-->
<?php
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( \'title\' => \'\') );
$title = $instance[\'title\'];
?>
<p><label for="<?php echo $this->get_field_id(\'title\'); ?>"><?php _e(\'Title:\'); ?> <input class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$new_instance = wp_parse_args((array) $new_instance, array( \'title\' => \'\'));
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
return $instance;
}
}
function mytheme_register_widgets()
register_widget( \'WP_Widget_Mood\' );
}
add_action( \'widgets_init\', \'mytheme_register_widgets\' );