Advertisement
hmbashar

WordPress conditional post

Apr 9th, 2015
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2. $the_query = new WP_Query( array( 'posts_per_page' => 7 ) );
  3. if ( $the_query->have_posts()) : ?>
  4. <?php $count = 0; ?>
  5. <?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
  6. <?php $count++; ?>
  7.  
  8.  
  9.  
  10.   <?php if ($count == 1) : ?>
  11.  
  12.     <div class="third_post single-latest">
  13.        <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
  14.         <?php the_post_thumbnail('post-image'); ?>
  15.         <?php the_excerpt(); ?>
  16.     </div>  
  17.    
  18.   <?php elseif ($count == 2) : ?>
  19.     <div class="fourth_post single-latest">      
  20.              
  21.         <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>
  22.         <?php the_post_thumbnail('post-image'); ?>
  23.         <?php the_excerpt(); ?>
  24.     </div>
  25.    
  26.    <?php else : ?>
  27.     <div class="single_post single-latest">
  28.          <a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a>        
  29.           <?php the_excerpt(); ?>
  30.     </div>
  31.    
  32.  
  33.    
  34.    
  35.  
  36. <?php endif; ?>
  37. <?php endwhile; ?>
  38. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement