在 Wordpress 中显示活动侧边栏 [英] Show active sidebar in Wordpress
问题描述
因此,如果没有要显示的小部件,我会尝试不显示侧边栏
当我使用 is_active_sidebar()
函数时,它总是返回 false 并且 if 语句不起作用,当我尝试使用 is_dynamic_sidebar()
函数时它总是返回真.
我安装了小部件逻辑插件,因此一些小部件显示在页面上,而有些页面没有小部件.
这是我的代码:
<?php if (is_dynamic_sidebar('left_bar')) { ?><div class="col-md-3 左侧边栏"><?phpdynamic_sidebar('left_bar');?><div class="col-md-9 main-content"><?php the_content('阅读更多');?>
<?php } else { ?><div class="col-md-12 main-content"><?php the_content('阅读更多');?>
<?php } ?>
对我应该做什么有任何想法吗?
您使用了错误的功能来检查活动侧边栏试试这个
if ( is_active_sidebar( 'left_bar' ) )dynamic_sidebar('left_bar');
So I'm trying to not show a side bar if it there are no widgets to show
when I use the is_active_sidebar()
function it always returns false and the if statement doesn't work and when I try to use the is_dynamic_sidebar()
function it always returns true.
I have the widget logic plugin installed so some of the widgets show up on a page and some pages don't have a widget.
This is my code:
<div class="row main-row">
<?php if (is_dynamic_sidebar('left_bar')) { ?>
<div class="col-md-3 left-sidebar">
<?php
dynamic_sidebar('left_bar');
?>
</div>
<div class="col-md-9 main-content">
<?php the_content('Read More'); ?>
</div>
<?php } else { ?>
<div class="col-md-12 main-content">
<?php the_content('Read More'); ?>
</div>
<?php } ?>
</div>
Any Ideas on what should I do?
You have used wrong function for checking active sidebar try this
if ( is_active_sidebar( 'left_bar' ) )
dynamic_sidebar( 'left_bar' );
这篇关于在 Wordpress 中显示活动侧边栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!