为特定页面添加备用,第二个侧边栏到wordpress

时间:2013-07-02 01:00:59

标签: php wordpress woocommerce sidebar

我有问题只在woocommerce单品页面上显示我的第二个右侧边栏。它根本不会显示出来。以下是我的所作所为。有什么不对或我错过了什么?

我将此添加到我的woocommerce页面,single-product.php文件

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

我已将侧边栏添加到我的wp-content&gt;主题&gt;主题&gt;包括&gt; 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 } ?>

2 个答案:

答案 0 :(得分: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>',
    ) );

答案 1 :(得分: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>