首页 文章

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

提问于
浏览
0

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

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

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

我已将侧边栏添加到我的wp-content> themes> theme> includes> 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

    我认为你需要在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

    我没有使用单独的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>
    

相关问题