如何在页面中添加我们的侧边栏

发现页面中page。php页侧边栏的小工具竟然没有办法显示。
第一、打开后台,点击外观-编辑-找到 function.php(模版函数)
加入

//add home or other
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
        'name' => 'home_sidebar',
        'id' => 'widget_homesidebar',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
    ));
    register_sidebar(array(
        'name'=> 'article_sidebar',
        'id' => 'widget_postsidebar',
        'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2>',
'after_title' => '</h2>',
    ));

}
//the another way
if( function_exists('register_sidebar') ) {  
    register_sidebar(array(  
    'name' => 'spage',  
    'before_widget' => '',  
    'after_widget' => '',  
    'before_title' => '<h3>',  
    'after_title' => '</h3>'  
            ));  
}  

接下来打开sidebar.php(边栏)
加入

//add the article sidebar
 if(is_home() || is_front_page()) { //首页显示“首页侧栏”
      if (function_exists('dynamic_sidebar') && dynamic_sidebar('widget_homesidebar')){} 
}
if ( is_single() ) {//文章页显示 “文章页侧栏”
      if (function_exists('dynamic_sidebar') && dynamic_sidebar('widget_postsidebar')){}
}
/*if (is_page()) {  
        dynamic_sidebar("spage")}*/
if ( is_page() ) {//文章页显示 “文章页侧栏”
      if (function_exists('dynamic_sidebar') && dynamic_sidebar('spage')){}
}

这样就可以成功加入边栏了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值