首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义侧栏的Woocommerce条件标记是十七个主题。

自定义侧栏的Woocommerce条件标记是十七个主题。
EN

Stack Overflow用户
提问于 2018-10-06 07:50:50
回答 1查看 200关注 0票数 0

我使用了二十七个主题和Woocommerce,并且希望我的woo商业页面有一个自定义的侧边栏,而不是默认的主题侧栏(侧栏-1),它将在站点的其他地方使用。

因此,在我的子主题的functions.php中,我注册了我的自定义侧栏(侧栏-6),用小部件填充它,并试图在我的子主题的sidebar.php中使用woo商业条件标记来调用它。

我是新的条件标签,尽管遵循各种在线网站的建议,到目前为止,还未能使这一工作。如果有人能为我指出正确的方向,我将非常感激。

最初的主题sidebar.php如下所示

代码语言:javascript
复制
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
return;
}
?>

<aside id="secondary" class="widget-area" role="complementary" 
aria-label="<?php esc_attr_e( 'Blog Sidebar', 'twentyseventeen' ); 
?>">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->

我尝试过不同的代码组合,试图使这个工作,但到目前为止,已失败。这是我目前拥有的,它不会在任何页面上显示侧边栏。

代码语言:javascript
复制
if ( is_woocommerce() ) : {
return;
}
?>

<aside id="secondary" class="widget-area" role="complementary" 
aria-label="<?php esc_attr_e( 'Shop Sidebar', 'twentyseventeen' );    
?>">
<?php dynamic_sidebar( 'sidebar-6' ); ?>
</aside><!-- #secondary -->


<?php else:
return;
}

?>
<aside id="secondary" class="widget-area" role="complementary" 
aria-label="<?php esc_attr_e( 'Blog Sidebar','twentyseventeen');         
?>">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->
<?php endif ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-06 08:09:45

您在以下情况下出错:

代码语言:javascript
复制
if ( is_woocommerce() ) : {
return;
  }

基本上,上面您是说,如果是Woocommerce页面,返回,什么也不做。

以下是正确的答案:

代码语言:javascript
复制
if ( is_woocommerce() && is_active_sidebar( 'sidebar-6' ) ) :?>
<aside id="secondary" class="widget-area" role="complementary" 
aria-label="
    <?php esc_attr_e( 'Shop Sidebar', 'twentyseventeen' ); ?>">
    <?php dynamic_sidebar( 'sidebar-2' ); ?>
</aside><!-- #secondary -->
    <?php
    elseif ( is_active_sidebar( 'sidebar-1' ) ) :
        ?>
<aside id="secondary" class="widget-area" role="complementary" 
aria-label="<?php esc_attr_e( 'Blog Sidebar', 'twentyseventeen' ); ?>">
        <?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- #secondary -->
<?php endif; ?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52676905

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档