2011-06-22 129 views
0

我想,如果下面的语句只出现在某些页面(例如,我不希望他们围绕整个结构,如果这是一个用户页面):将php if语句应用于另一个if语句?

<div class="mainbar"> 

    <?php if /* I don't want this and... */ (bbp_has_topics($bbp_loop_args)) : ?> 

     <?php while (bbp_topics()) : bbp_the_topic(); ?> 

      <div class="topic-wrapper"> 
       <div class="topic-left"> 
        <h2><a href="<?php bbp_topic_permalink(); ?>" title="<?php bbp_topic_title(); ?>"><?php bbp_topic_title(); ?></a></h2> 
        <span><?php printf(__('Started by: %1$s', 'bbpress'), bbp_get_topic_author_link(array('size' => '14'))); ?></span> 

        <?php if (!bbp_is_forum() || (bbp_get_topic_forum_id() != bbp_get_forum_id())) : ?> 
         <span class="bbp-topic-started-in"><?php printf(__('in: <a href="%1$s">%2$s</a>', 'bbpress'), bbp_get_forum_permalink(bbp_get_topic_forum_id()), bbp_get_forum_title(bbp_get_topic_forum_id())); ?></span> 
        <?php endif; ?> 

        <?php bbp_topic_tag_list(); ?> 

       </div><!-- #topic-left --> 

       <div class="topic-right"> 
        <div class="topic-like-count"> 
         <h4><?php // bbp_topic_reply_count(); ?><?php if(function_exists('the_ratings')) { the_ratings(); } ?></h4> 
         <span><?php _e('likes'); ?></span> 
        </div> 

        <div class="topic-reply-count"> 
         <h4><?php bbp_topic_reply_count(); ?></h4> 
         <span><?php _e('replies'); ?></span> 
        </div> 

        <div class="topic-freshness"> 
         <h4><?php bbp_topic_freshness_link(); ?></h4> 
          <span> 
           <?php bbp_author_link(array('post_id' => bbp_get_topic_last_active_id(), 'size' => 14)); ?> 
          </span> 
        </div> 
       </div><!-- #topic-right --> 
      </div><!-- #topic --> 

     <?php /* this to appear in an user page */ endwhile; ?> 

    <?php endif; ?> 

     </div><!-- #mainbar --> 

这是if语句我应该用来确保if语句不包围用户页面中的整个结构:

<?php if (! is_single('user')) : ?> 

<?php endif; ?> 

但是我不知道如何或在何处放置它。

有什么建议吗?

+0

对不起,我不明白你的意思。 – phant0m

+0

@ phant0m if语句'<?php while(bbp_topics()):bbp_the_topic(); ''不应该只在某些页面中围绕整个结构。如果结构中没有if语句,则某些页面才有效。 – alexchenco

+0

“if语句:while” - 什么是while语句?所以基本上,你希望某些控制结构只能在特定的页面上工作。你需要检查他们。假设你有一个允许的站点数组和一个当前站点的变量:'if(in_array($ site,$ allowed_sites)&&())' – phant0m

回答

3

如果我理解正确的话,你可以简单地替换:

if (bbp_has_topics($bbp_loop_args)) : 

由:

if (is_single('user') || bbp_has_topics($bbp_loop_args)) : 

这样,第二个条件是只有当第一个条件是false应用。