Advertisement
Guest User

dudd

a guest
Jan 10th, 2011
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // initiate the default wordpress loop as usual
  2. <?php if (have_posts()) : while(have_posts()) :
  3.  
  4. // set a count variable to increase with each loop
  5. $i++;
  6.  
  7. // test the variable modulus against a zero value
  8. // odd values return true, even values return false
  9. // see proceding discussion for more information
  10. if(($i % 2) == 0) :
  11.  
  12. // skip to next post if variable is an even number
  13. $wp_query->next_post();
  14.  
  15. // display the post if variable is an odd number
  16. else : the_post(); ?>
  17.  
  18. // open a division for the left column
  19. <div id="left-column">
  20.  
  21. // display the title of the post
  22. <h1><?php the_permalink(); ?></h1>
  23.  
  24. // display the post content
  25. <?php the_content(); ?>
  26.  
  27. // close the division
  28. </div>
  29.  
  30. // close the first if statement
  31. <?php endif;
  32.  
  33. // close the loop
  34. endwhile;
  35.  
  36. // if there are no posts that meet the criteria
  37. else: ?>
  38.  
  39. // display some alternate content
  40. <div>Alternate content</div>
  41.  
  42. // close the second if statement
  43. <?php endif; ?>
  44.  
  45. // reset the count variable to zero
  46. <?php $i = 0;
  47.  
  48. // reset the loop
  49. rewind_posts(); ?>
  50.  
  51. // the second loop is essentially the same as the first
  52. // the only difference is that we are testing the count variable against a non-zero value to display only even numbers
  53. <?php if (have_posts()) : while(have_posts()) : $i++; if(($i % 2) !== 0) : $wp_query->next_post(); else : the_post(); ?>
  54.  
  55. // and of course a unique div id for the right column
  56. <div id="right-column">
  57. <h1><?php the_permalink(); ?></h1>
  58. <?php the_content(); ?>
  59. </div>
  60.  
  61. <?php endif; endwhile; else: ?>
  62. <div>Alternate content</div>
  63. <?php endif; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement