douqingzhi0980 2017-04-18 15:58
浏览 25

替换没有插件的子页面的侧边栏

I'm trying to get a different sidebar to load within child pages of a particular parent without the use of a plugin or setting up another template file.

This is what I have so far:

register_sidebars(1, array(
'name' => 'Other Sidebar',
'id' => "other-sidebar",
'before_widget' => '<li class="widget">',
'after_widget' => '</li>',
'before_title' => '<span class="widgettitle">',
'after_title' => '</span>'
));

if ( $post->post_parent == '1164' ) {
dynamic_sidebar( 'other-sidebar' );
}

But I'm wondering if I need use a filter of some sort to replace the default sidebar that is being loaded instead? Not too sure if that's correct or not.

  • 写回答

1条回答 默认 最新

  • dongying7667 2017-04-18 16:26
    关注

    Since you can edit the theme (or child theme) you could add a Page Template that would override the current page template with the custom sidebar you want.

    <?php 
    /*
    Template Name: Custom Sidebar Page // All versions
    Template Post Type: page // 4.7+ only
    */
    
    // Page code here with the sidebar you want...
    ?>
    
    <aside id="secondary" class="widget-area" role="complementary">
        <?php dynamic_sidebar( 'other-sidebar' ); ?>
    </aside><!-- #secondary -->
    

    Then, in the edit for your page and it's child pages, set this template as the one you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line