【问题标题】:Add alternate, 2nd sidebar to wordpress for specific page(s)为特定页面添加备用的第二个侧边栏到 wordpress
【发布时间】:2013-07-02 01:00:58
【问题描述】:

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

我将此添加到我的 woocommerce 页面,single-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 } ?>

【问题讨论】:

  • 您将侧边栏文件包含为 sidebar2.php,但您将文件创建为 sidebar5.php...
  • 错字 - 仍然不显示侧边栏

标签: php wordpress woocommerce sidebar


【解决方案1】:

我认为您需要在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>',
    ) );

【讨论】:

  • 我的主题 functions.php 通过调用该 sidebars.php 文件来处理它,其中我的代码与您发布的相同。 require_once( $template_directory . '/includes/functions/sidebars.php' );
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-20
    • 1970-01-01
    • 2011-04-14
    • 2013-01-16
    • 2020-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多