将#侧边栏-2添加到自定义页面模板

时间:2013-04-24 作者:Astoria

我注册了一些自定义侧栏,我的Twentyle2Theme版本中的相应代码现在如下所示:

    register_sidebar( array(
    \'name\' => __( \'Sidebar #1\', \'twentytwelve\' ),
    \'id\' => \'sidebar-1\',
    \'description\' => __( \'Appears on posts and pages except the optional Front Page template, which has its own widgets\', \'twentytwelve\' ),
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\' => \'</aside>\',
    \'before_title\' => \'<h3 class="widget-title">\',
    \'after_title\' => \'</h3>\',
) );

register_sidebar( array(
    \'name\' => __( \'Sidebar #2\', \'twentytwelve\' ),
    \'id\' => \'sidebar-2\',
    \'description\' => __( \'Appears on posts and pages except the optional Front Page template, which has its own widgets\', \'twentytwelve\' ),
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\' => \'</aside>\',
    \'before_title\' => \'<h3 class="widget-title">\',
    \'after_title\' => \'</h3>\',
) );

register_sidebar( array(
    \'name\' => __( \'Sidebar #3\', \'twentytwelve\' ),
    \'id\' => \'sidebar-3\',
    \'description\' => __( \'Appears on posts and pages except the optional Front Page template, which has its own widgets\', \'twentytwelve\' ),
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\' => \'</aside>\',
    \'before_title\' => \'<h3 class="widget-title">\',
    \'after_title\' => \'</h3>\',
) );

register_sidebar( array(
    \'name\' => __( \'Sidebar #4\', \'twentytwelve\' ),
    \'id\' => \'sidebar-4\',
    \'description\' => __( \'Appears on posts and pages except the optional Front Page template, which has its own widgets\', \'twentytwelve\' ),
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\' => \'</aside>\',
    \'before_title\' => \'<h3 class="widget-title">\',
    \'after_title\' => \'</h3>\',
) );

register_sidebar( array(
    \'name\' => __( \'Sidebar #5\', \'twentytwelve\' ),
    \'id\' => \'sidebar-5\',
    \'description\' => __( \'Appears on posts and pages except the optional Front Page template, which has its own widgets\', \'twentytwelve\' ),
    \'before_widget\' => \'<aside id="%1$s" class="widget %2$s">\',
    \'after_widget\' => \'</aside>\',
    \'before_title\' => \'<h3 class="widget-title">\',
    \'after_title\' => \'</h3>\',
) );
我的自定义页面模板使用#侧边栏-1:

<div id="inner-page-sidebar">

<?php get_sidebar(); ?>

</div> <!-- END INNER-PAGE-SIDEBAR -->
现在,我想创建一个单独的自定义页面模板#2,它应该与自定义页面模板#1相同,只是它应该使用#提要栏-2而不是#提要栏-1。

Question: 我应该如何将备选侧边栏放在那里?

提前感谢您的帮助!

2 个回复
最合适的回答,由SO网友:Tom J Nowell 整理而成

而不是打电话get_sidebar() 呼叫get_sidebar( \'somethingelse\' );. 它将尝试加载sidebar-somethingelse.php 如果不存在,它将加载sidebar.php. 然后可以修改sidebar-somethingelse.php 加载不同的侧栏等

我强烈建议您查看template hierarchy 作品

SO网友:Jamie

查看模板中的侧边栏页面。您需要的所有代码都已经存在。你会看到

  if( is_active(\'sidebar-1\')){
      get_sidebar(\'sidebar-1\');
  }
我不确定确切的代码,因为我没有坐在电脑前处理文件。您所需要做的就是复制该代码并更改名称以匹配侧栏。有几页你可以看看。就像侧边栏。php,首页。模板目录中的phhp。这应该叫一到两个侧边栏。

结束

相关推荐

Register/Get sidebar?

我似乎不太明白它是怎么工作的。默认情况下,我在侧栏中有一个侧栏。我使用加载的phpget_sidebar();. 这很好(无需注册),但我有一个自定义页面模板,用于另一个页面,我想加载另一个侧栏。我知道我可以使用include(\'filename\')来加载它,但我假设也有某种wordpress方法来加载它。我知道我必须在函数中注册新的侧栏。php文件,但我实际上在哪里引用侧栏文件?从文档:name - Sidebar name (default is localized \'Sidebar\' and