我们如何在网站上添加另一个左侧边栏

时间:2012-12-20 10:46:37

标签: wordpress twitter-bootstrap sidebar

我正在使用bootstrap theme.i m在wordpress上使用我的网站上的主左侧边栏。我将代码放入WIDGETS> MainSidebar但现在我有一个问题,点击链接我想打开另一个页面,与我的主页相同,但不同的侧栏。我可以实现吗?

这是我的bootstrap模板:页面模板(page.php)

<?php
/** page.php
 *
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @author      Konstantin Obenland
 * @package     The Bootstrap
 * @since       1.0.0 - 07.02.2012
 */

get_header(); ?>

<div id="primary" class="span9">
    <?php tha_content_before(); ?>
    <div id="content" role="main">
        <?php tha_content_top();

        the_post();
        get_template_part( '/partials/content', 'page' );
        comments_template();

        tha_content_bottom(); ?>
    </div><!-- #content -->
    <?php tha_content_after(); ?>
</div><!-- #primary -->

<?php
get_sidebar();
get_footer();


/* End of file page.php */
/* Location: ./wp-content/themes/the-bootstrap/page.php */

1 个答案:

答案 0 :(得分:1)

您必须有两个不同的侧边栏。 将侧边栏代码放在您喜欢的自定义模板名称中。

了解如何创建自定义模板link

并使用wordpress条件标签,如。

if(is_page( 2 )){ // 2 is page id
get_template_part( 'custom', 'sidebar' ); //  (custom-sidebar.php)
}
else{ 
get_sidebar();
}

conditionnal tags

通过这种方式,您可以在不同的页面上放置2个侧边栏。