2013-07-02 20 views
0

我有一个问题,显示我的第二个右侧边栏只在woocommerce单品页面。它根本不会显示它。以下是我所做的。什么是错的或我错过了什么?针对特定页面添加备用,第二条边栏到wordpress

我将此添加到我的woocommerce页,单product.php文件

<?php 
     /** 
     * woocommerce_sidebar hook 
     * 
     * @hooked woocommerce_get_sidebar - 10 
     */ 
     /* do_action('woocommerce_sidebar'); */ 
      include("sidebar5.php"); 
?> 

我已经添加了侧边栏到我的wp-content>主题>主题>包括> sidebars.php文件。它已经有4个侧边栏(一个正确和三个页脚):

register_sidebar(array(
     'name' => 'Sidebar Woo', 
     'id' => 'sidebar-5', 
     'before_widget' => '<div id="%1$s" class="widget %2$s">', 
     'after_widget' => '</div> <!-- end .widget -->', 
     'before_title' => '<h4 class="widgettitle">', 
     'after_title' => '</h4>', 
    )); 

我创建了一个页面sidebar5.php:

<?php if (is_active_sidebar('sidebar-5')){ ?> 
    <div id="sidebar"> 
     <?php dynamic_sidebar('sidebar-5'); ?> 
    </div> <!-- end #sidebar --> 
<?php } ?> 
+0

您包括侧边栏文件sidebar2.php但您所创建的文件作为sidebar5.php ... – designtocode

+0

错字 - 仍然没有显示侧边栏 – sloga

回答

0

我认为你需要在functions.php中添加以下代码,而不是创建其他文件。

register_sidebar(array(
     'name' => 'Sidebar Woo', 
     'id' => 'sidebar-5', 
     'before_widget' => '<div id="%1$s" class="widget %2$s">', 
     'after_widget' => '</div> <!-- end .widget -->', 
     'before_title' => '<h4 class="widgettitle">', 
     'after_title' => '</h4>', 
    )); 
+0

我的主题的functions.php通过调用sidebars.php文件处理它我的代码与您发布的代码相同。 require_once($ template_directory。'/includes/functions/sidebars.php'); – sloga

0

而不是使用单独的sidebar5.php页面我把代码直接放在woocommerce single-product.php中,并删除了include。

<?php 
     /** 
     * woocommerce_sidebar hook 
     * 
     * @hooked woocommerce_get_sidebar - 10 
     */ 
     /* do_action('woocommerce_sidebar'); */ 
      // include("sidebar5.php"); 
?> 
<?php if (is_active_sidebar('sidebar-5')) : ?> 
    <div id="sidebar"> 
     <?php dynamic_sidebar('sidebar-5'); ?> 
    </div> 
相关问题