Title: Display posts from specific category within loop
Last modified: August 19, 2016

---

# Display posts from specific category within loop

 *  [netbuddy34](https://wordpress.org/support/users/netbuddy34/)
 * (@netbuddy34)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/display-posts-from-specific-category-within-loop/)
 * I have the following piece of code in my home.php
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post();
         if($post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
       ```
   
 * It cycles through and displays single posts from any category. I want to change
   that so it only displays a specific category – category 3
 * The entire code looks like this…but I think the above part is where I need to
   make the changes.
 *     ```
       <!--Begin recent post (single)-->
   
       <?php if (have_posts()) : while (have_posts()) : the_post();
         if($post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
   
       <?php static $ctr = 0;
       if ($ctr == "$artsee_homepage_posts;") { break; }
       else { ?>
   
       <?php
       // check for thumbnail
       $thumb = get_post_meta($post->ID, 'Thumbnail', $single = true);
       // check for thumbnail class
       $thumb_class = get_post_meta($post->ID, 'Thumbnail Class', $single = true);
       // check for thumbnail alt text
       $thumb_alt = get_post_meta($post->ID, 'Thumbnail Alt', $single = true);
       ?>
       <div class="home-post-wrap2">
       <span class="headings">Network</span>
       <div class="post-info">Posted by <?php the_author() ?>  on  <?php the_time('m jS, Y') ?> |  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></div>
       <span class="titles"><a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></span>
       <div style="clear: both;"></div>
       <!--Display thumbnail if found-->
       <div class="thumbnail-div-home">
       <?php // if there's a thumbnail
       if($thumb !== '') { ?>
       <a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/phpThumb/phpThumb.php?src=<?php echo $thumb; ?>&amp;h=130&amp;w=281&amp;zc=1&amp;q=100" alt="<?php if($thumb_alt !== '') { echo $thumb_alt; } else { echo the_title(); } ?>"  style="border: none;" /></a>
       <?php } // end if statement
       // if there's not a thumbnail
       else { echo ''; } ?>
       </div>
       <!--End display thumbnail if found-->
       <?php if (function_exists('the_content_limit')) { the_content_limit(400, ""); } else { echo 'You have not uploaded and acivated the limit posts plugin. This is required.'; } ?>
       <div class="readmore"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">Read More</a></div>
       </div>
   
       <?php $ctr++; } ?>
   
       <?php endwhile; ?>
       <!--end recent post (single)-->
       ```
   

Viewing 1 replies (of 1 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/display-posts-from-specific-category-within-loop/#post-874150)
 * See the **cat=** parameter for the [template tag](http://codex.wordpress.org/Template_Tags),
   [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts).

Viewing 1 replies (of 1 total)

The topic ‘Display posts from specific category within loop’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [17 years, 8 months ago](https://wordpress.org/support/topic/display-posts-from-specific-category-within-loop/#post-874150)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
