Title: Post Loop
Last modified: August 19, 2016

---

# Post Loop

 *  [jbert](https://wordpress.org/support/users/jbert/)
 * (@jbert)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/post-loop-1/)
 * Here is the code I am using for my post.
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=4"); while($recent->have_posts()) : $recent->the_post();?>
   
       <div class="post">
       <h2 class="postTitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
       <div class="postMeta">
       <span class="date"><?php the_time('M.d, Y') ?></span> in
       <span class="filed"><?php the_category(', '); ?></span>
       <span class="commentcount"><?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?></span>
       </div>
       <div class="postContent"><?php the_content(); ?></div>
       </div> <!-- Closes Post -->
   
       <?php endwhile; ?>
       ```
   
 * but if I try to add
 * `<?php else; ?>`
 * it throws an error. Where am I going wrong
 * Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Tynan Beatty](https://wordpress.org/support/users/junsuijin/)
 * (@junsuijin)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/post-loop-1/#post-1094620)
 * Not exactly sure what you mean, but I think you want to format it more like a
   traditional WordPress loop:
 *     ```
       <?php $recent = new WP_Query("cat=1&showposts=4"); 
   
       if ($recent->have_posts()) :
   
       while($recent->have_posts()) : $recent->the_post();?>
   
       <div class="post">
       <h2 class="postTitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
       <div class="postMeta">
       <span class="date"><?php the_time('M.d, Y') ?></span> in
       <span class="filed"><?php the_category(', '); ?></span>
       <span class="commentcount"><?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?></span>
       </div>
       <div class="postContent"><?php the_content(); ?></div>
       </div> <!-- Closes Post -->
   
       <?php endwhile;
   
       else :
   
       //put your else code here
   
       endif; ?>
       ```
   
 * peace~
 *  Thread Starter [jbert](https://wordpress.org/support/users/jbert/)
 * (@jbert)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/post-loop-1/#post-1094633)
 * Thanks, I did that first and added the wp-query for the category before the loop
   and all worked fine. I have another theme that uses this variable type and was
   trying to include it.
 * Thanks
 * JIM

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Post Loop’ is closed to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * 2 replies
 * 2 participants
 * Last reply from: [jbert](https://wordpress.org/support/users/jbert/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/post-loop-1/#post-1094633)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
