2012-01-02 24 views
0

我正在为我的网站制作一个WordPress主题。我想要一个小的帮助,因为我不是php的专家。我的问题是这样的:如何检查多个侧边栏存在?

我有一个侧边栏DIV再次内有4个侧边栏:

<div id="jp-double-bar" class="equal"> 
    <?php if (is_active_sidebar('double-top')) : ?> 
    <div class="jp-double-top"> 
     <?php dynamic_sidebar('double-top'); ?> 
    </div> 
    <?php endif; ?> 
    <div class="double-middle"> 
     <?php if (is_active_sidebar('middle-2')) : ?> 
     <div class="jp-middle-2 equalmiddle"> 
      <?php dynamic_sidebar('middle-2'); ?> 
     </div> 
     <?php endif; ?> 
     <?php if (is_active_sidebar('middle-1')) : ?> 
     <div class="jp-middle-1 equalmiddle"> 
      <?php dynamic_sidebar('middle-1'); ?> 
     </div> 
     <?php endif; ?> 
    </div> 
    <?php if (is_active_sidebar('double-bottom')) : ?> 
    <div class="jp-double-bottom"> 
     <?php dynamic_sidebar('double-bottom'); ?> 
    </div> 
    <?php endif; ?> 
</div> 

这里我的问题是,如果我不发表任何部件中任何一个侧栏,仍出现外部<div id="jp-double-bar">

我的问题是.......我们用单独的边栏打包<?php if():?>语句的方式,有没有办法用4个if语句来包装主外部div。

就像没有在4个侧边栏中的任何一个中发布的小部件一样,那么主外部div应该不会显示。

请帮忙。

问候

回答

1

看来,你必须要使用wp_get_sidebars API调用来检索吧。检查并查看它是否具有零(空)的长度。

或者只是使用和声明

if (is_active_sidebar('double-bottom') && is_active_sidebar('') && ...) {} 
+0

您可能还需要检查出http://wordpress.stackexchange.com这是在回答WP API的问题更好。 – mrtsherman 2012-01-02 04:14:17

+0

Yaahoooooo !!!它完美的作品。非常感谢好友。 – 2012-01-02 04:27:02