我几乎没有创建widget区域的经验,我一直在将widget保存在widget区域的“红色菜单”中。我已经搜索了十几篇帖子,但似乎都没找到。
我目前在Wordpress 4.0.1中工作,这是我的代码:
小部件。php:
class Red_Menu_Widget extends WP_Widget {
function redmenu_widget( $args, $instance ) {
$widget_ops = array(
\'classname\' => \'redmenu_widget\',
\'description\' => __(\'Description in here\')
$control_ops = array( \'width\' => 300, \'height\' => 350, \'id_base\' => \'redmenu_widget\' );
$this->WP_Widget( \'redmenu_widget\', __(\'Rood menu rechts\', \'redmenu_widget\'), $widget_ops, $control_ops );
);
//parent::WP_Widget(false, \'Rood menu (rechts)\', $widget_ops );
}
function widget() {
$title = \'Rood menu (rechts)\';
echo $before_widget;
echo $title;
echo \'<p>This is my widget output</p>\';
echo $after_widget;
}
}
add_action( \'widgets_init\', \'prefix_register_widgets\' );
function prefix_register_widgets() {
register_widget( \'redmenu_widget\' );
}
功能。php:function pfp_widgets_init() {
register_sidebar( array (
\'name\' => __( \'Rood menu (rechts)\', \'powerforpaws\' ),
\'id\' => \'redmenu_widget\',
\'description\' => __( \'Descriptionhere\', \'powerforpaws\' ),
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => "</li>",
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
} // end pfp_widgets_init
add_action( \'widgets_init\', \'pfp_widgets_init\' );
// Pre-set Widgets
$preset_widgets = array (
\'redmenu_widget\' => array( \'search\', \'pages\', \'categories\', \'archives\' )
);
if ( !isset( $_GET[\'activated\'] ) ) {
update_option( \'sidebars_widgets\', $preset_widgets );
}
侧栏。php:<aside id="widgets">
<?php if ( !function_exists(\'redmenu_widget\') || !dynamic_sidebar(\'redmenu_widget\') ) : ?>
<div id="primary" class="widget-area">
<ul class="xoxo">
<?php dynamic_sidebar(\'redmenu_widget\'); ?>
</ul>
</div><!-- #primary .widget-area -->
<?php endif; ?>
</aside>
我做错了什么?提前感谢!