wordpress启用侧边栏小工具

http://www.seo628.com/1872.html

wordpress后台默认不显示小工具选项,开发者需要启用小工具功能并把小工具在相应的前台位置调用出来,这样才能在后台直接拖动生成侧边栏。

激活小工具

激活小工具需要在functions.php中注册至少一个侧边栏

register_sidebar( array(
'name' => __( '默认侧边栏', 'Bing' ),
'id' => 'widget_default',
'description' => __( '侧边栏的描述', 'Bing' ),
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
) );

这样在外观下就可以看到小工具按钮了

wordpress启用侧边栏小工具

拖动需要的小工具进行设置

前台调用

<?php dynamic_sidebar( 'widget_default' ); ?>

使用the_widget()函数直接调用小工具

<?php the_widget($widget, $instance, $args); ?>

参数$widget,小工具类名

  • WP_Widget_Archives – 存档小工具
  • WP_Widget_Calendar – 日历小工具
  • WP_Widget_Categories – 分类小工具
  • WP_Widget_Links – 链接小工具
  • WP_Widget_Meta – Meta小工具
  • WP_Widget_Pages – 页面小工具
  • WP_Widget_Recent_Comments – 最近评论小工具
  • WP_Widget_Recent_Posts – 最新文章小工具
  • WP_Widget_RSS – RSS小工具
  • WP_Widget_Search – 搜索小工具
  • WP_Widget_Tag_Cloud – 标签云小工具
  • WP_Widget_Text – 文本小工具
  • WP_Nav_Menu_Widget – 菜单小工具

参数$instance

扫描二维码关注公众号,回复: 6513092 查看本文章

表示每个widget的设置,例如Archives是用dropdown菜单显示还是列表显示

参数$args

widget的sidebar参数,包括before_widget、after_widget、before_title和after_title

调用文章归档小工具举例

<?php the_widget('WP_Widget_Recent_Posts'); ?>

猜你喜欢

转载自blog.csdn.net/james_laughing/article/details/92390560