将if语句添加到PHP模板

将if语句添加到PHP模板,php,wordpress,if-statement,visual-composer,Php,Wordpress,If Statement,Visual Composer,为了确定基于$num变量显示的布局,我想在下面的模板中添加if语句。然而,我无法让我的if,elseif语句工作!(新手!)非常感谢您的帮助 这是当前模板: <?php $count = 1; $query_args = array('post_type' => 'bunch_team' , 'showposts' => $num, 'order_by' => $sort , 'order' => $order); if( $cat )

为了确定基于$num变量显示的布局,我想在下面的模板中添加if语句。然而,我无法让我的if,elseif语句工作!(新手!)非常感谢您的帮助

这是当前模板:

<?php  
   $count = 1;
   $query_args = array('post_type' => 'bunch_team' , 'showposts' => $num, 
   'order_by' => $sort , 'order' => $order);
   if( $cat ) $query_args['team_category'] = $cat;
   $query = new WP_Query($query_args) ; 
   ob_start() ;?>
   <?php if($query->have_posts()):  ?>   <!--Our Team Section-->
   <section class="team-section">
    <div class="auto-container">
        <div class="sec-title">
            <h2><?php echo balanceTags($title);?></h2>
            <div class="separator"></div>
            <div class="heading-text"><?php echo balanceTags($sub_title);?>
            </div>
        </div>

        <div class="row clearfix">

            <?php while($query->have_posts()): $query->the_post();
                global $post ; 
                $teams_meta = _WSH()->get_meta();
                $post_thumbnail_id = get_post_thumbnail_id($post->ID);
                $post_thumbnail_url = wp_get_attachment_url( 
                $post_thumbnail_id );
               ?>  
            <!--Member-->
            <article class="col-md-3 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 
                        'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), 
                        $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 
                    'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo 
                                    esc_url(convo_set($value, 
                                    'social_link'));?>" class="fa <?php echo 
                                     convo_set($value, 'social_icon');?>">
                                     </a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
        <?php endwhile;?>   
        </div>
    </div>
</section>


<?php endif; ?>
<?php 
   wp_reset_postdata();
   $output = ob_get_contents(); 
   ob_end_clean(); 
   return $output ; ?>



我想根据$num变量更改文章布局例如,如果$num==2,文章布局应该是:

                <article class="col-md-6 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-4 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-3 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>


如果$num==3,文章布局应为:

                <article class="col-md-6 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-4 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-3 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>


如果$num==4,文章布局应为:

                <article class="col-md-6 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-4 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>
                <article class="col-md-3 col-sm-6 col-xs-12 member-column">
                <div class="inner-box">
                    <figure class="image">
                        <?php the_post_thumbnail('convo_size_team');?>
                    </figure>
                    <div class="member-title">
                        <h4><?php the_title();?></h4>
                        <p><?php echo convo_set($teams_meta, 'designation');?></p>
                    </div>
                    <div class="member-desc">
                        <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                    </div>
                    <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                    <ul class="social-links clearfix">

                        <?php foreach($socials as $key => $value):?>
                                    <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                            <?php endforeach;?>
                    </ul>
                    <?php endif;?>
                </div>
            </article>


任何帮助都将不胜感激。我大致知道怎么做,但无法让if语句根据$num变量仅正确显示正确的布局

干杯

像这样的

<?php
$count = 1;

$query_args = array(
  'post_type' => 'bunch_team',
  'showposts' => $num,
  'order_by' => $sort,
  'order' => $order
);

if ( $cat ) {
  $query_args['team_category'] = $cat;
}

$query = new WP_Query( $query_args ); ?>
<?php if($query->have_posts()):  ?>   <!--Our Team Section-->
  <section class="team-section">
    <div class="auto-container">
      <div class="sec-title">
        <h2><?php echo balanceTags($title);?></h2>
        <div class="separator"></div>
        <div class="heading-text"><?php echo balanceTags($sub_title);?>
        </div>
      </div>

      <div class="row clearfix">
        <?php while($query->have_posts()) : $query->the_post();
          global $post;
          $teams_meta = _WSH()->get_meta();
          $post_thumbnail_id = get_post_thumbnail_id($post->ID);
          $post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id );
          if ( $num === 2 ) { // Must be number! Instead use '2'
          ?>
          <article class="col-md-6 col-sm-6 col-xs-12 member-column">
              <div class="inner-box">
                  <figure class="image">
                      <?php the_post_thumbnail('convo_size_team');?>
                  </figure>
                  <div class="member-title">
                      <h4><?php the_title();?></h4>
                      <p><?php echo convo_set($teams_meta, 'designation');?></p>
                  </div>
                  <div class="member-desc">
                      <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                  </div>
                  <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                  <ul class="social-links clearfix">

                      <?php foreach($socials as $key => $value):?>
                                  <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                          <?php endforeach;?>
                  </ul>
                  <?php endif;?>
              </div>
          </article>
          <?php 
          } elseif ( $num === 3 ) {
          ?>
          <article class="col-md-4 col-sm-6 col-xs-12 member-column">
              <div class="inner-box">
                  <figure class="image">
                      <?php the_post_thumbnail('convo_size_team');?>
                  </figure>
                  <div class="member-title">
                      <h4><?php the_title();?></h4>
                      <p><?php echo convo_set($teams_meta, 'designation');?></p>
                  </div>
                  <div class="member-desc">
                      <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                  </div>
                  <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                  <ul class="social-links clearfix">

                      <?php foreach($socials as $key => $value):?>
                                  <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                          <?php endforeach;?>
                  </ul>
                  <?php endif;?>
              </div>
          </article>
          <?php 
          } elseif ( $num === 4 ) {
          ?>
            <article class="col-md-3 col-sm-6 col-xs-12 member-column">
              <div class="inner-box">
                  <figure class="image">
                      <?php the_post_thumbnail('convo_size_team');?>
                  </figure>
                  <div class="member-title">
                      <h4><?php the_title();?></h4>
                      <p><?php echo convo_set($teams_meta, 'designation');?></p>
                  </div>
                  <div class="member-desc">
                      <p><?php echo convo_trim(get_the_excerpt(), $text_limit);?></p>
                  </div>
                  <?php if($socials = convo_set($teams_meta, 'bunch_team_social')):?>
                  <ul class="social-links clearfix">

                      <?php foreach($socials as $key => $value):?>
                                  <li><a href="<?php echo esc_url(convo_set($value, 'social_link'));?>" class="fa <?php echo convo_set($value, 'social_icon');?>"></a></li>
                          <?php endforeach;?>
                  </ul>
                  <?php endif;?>
              </div>
            </article>
          <?php 
          } else {
            <article class="col-md-3 col-sm-6 col-xs-12 member-column">
            <div class="inner-box">
              <figure class="image">
                <?php the_post_thumbnail('convo_size_team');?>
              </figure>
              <div class="member-title">
                <h4><?php the_title();?></h4>
                <p><?php echo convo_set($teams_meta, 
                  'designation');?></p>
                </div>
                <div class="member-desc">
                  <p><?php echo convo_trim(get_the_excerpt(), 
                    $text_limit);?></p>
                  </div>
                  <?php if($socials = convo_set($teams_meta, 
                  'bunch_team_social')):?>
                  <ul class="social-links clearfix">

                    <?php foreach($socials as $key => $value):?>
                      <li><a href="<?php echo 
                        esc_url(convo_set($value, 
                        'social_link'));?>" class="fa <?php echo 
                        convo_set($value, 'social_icon');?>">
                      </a></li>
                    <?php endforeach;?>
                  </ul>
                <?php endif;?>
              </div>
            </article>
          <?php 
          }
          endwhile;?> 
        </div>
      </div>
    </section>
<?php endif;
wp_reset_postdata();









感谢dingo_d,我大致就是这么做的,但是页面只是加载空白。这是wordpress visual composer元素的模板,添加元素时,通过vc页面编辑器提供$num。