我有一个通过小工具显示产品菜单的主题。我们可以通过下面的代码显示/隐藏这些类别(侧边栏)。现在,如果两个产品类别中的一个有小部件,它就会显示/隐藏这个carousel-item。我们希望保留此功能,但如果类别为空,则将其隐藏。例如,如果有产品在类别1中,但不在类别2中,我们希望隐藏整个部分(请参阅代码中的注释,了解我们想要隐藏的位置。
<?php if ( is_active_sidebar( 'widget-category-1' ) || is_active_sidebar('widget-category-2') ) { ?>
<div class="carousel-item active animated fadeIn">
<div class="d-block w-100">
//show or hide start here//
<div class="container-fluid px-5">
<div class="row">
<ul class="three-col">
<?php dynamic_sidebar( 'widget-category-1' ); ?>
</ul>
</div>
</div>
//show or hide end here//
//show or hide start here//
<div class="container-fluid">
<div class="row">
<ul class="three-col">
<?php dynamic_sidebar( 'widget-category-2' ); ?>
</ul>
</div>
</div>
//show or hide end here//
</div>
</div>
<?php } ?>`发布于 2019-10-07 05:40:07
可以使用first-of-type或nth-of-type来引用要切换的元素。这或者可能是一个not()伪类应该可以做到这一点。
我在你的问题中添加了一个CSS标签。您需要添加dynamic_sidebar返回的元素的其余部分,以确保这一点,但通常有一个‘has-item’标识符可以引用。
发布于 2019-10-08 04:13:23
我们最终将每个部分包装在一个<div class="phide"></div>中,如果没有<li></li>,则使用javascript隐藏this div。
<script>
(function($) {
$( document ).ready(function() {
$('.phide:not(:has(li))').hide();
});
})(jQuery);
</script>https://stackoverflow.com/questions/58261323
复制相似问题