Title: Same loop, different formatting depending on category?
Last modified: August 19, 2016

---

# Same loop, different formatting depending on category?

 *  [greasypigstudios](https://wordpress.org/support/users/greasypigstudios/)
 * (@greasypigstudios)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/)
 * I have one loop that shows posts from different categories. I would like to be
   able to display posts from one category in one way (say, with a thumbnail), and
   another category another way (i.e., just the excerpt).
 * Help?

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

 *  [@mercime](https://wordpress.org/support/users/mercime/)
 * (@mercime)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/#post-1169354)
 * Viola! [Category Templates](http://codex.wordpress.org/Category_Templates)
 *  Thread Starter [greasypigstudios](https://wordpress.org/support/users/greasypigstudios/)
 * (@greasypigstudios)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/#post-1169544)
 * Thanks for the help, but nothing I saw there referred me to what I should do 
   if I wanted to show posts from differing categories all on the ONE SAME loop (
   like the main index), but the formatting would be different depending on what
   category the post is.
 *  Thread Starter [greasypigstudios](https://wordpress.org/support/users/greasypigstudios/)
 * (@greasypigstudios)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/#post-1169550)
 * I’ve gotten as far as thinking it’ll be a conditional tag inside the loop, but
   I’m having a hard time getting it to determine whether a specific post is from
   one category or another:
 *     ```
       <?php
       query_posts('&showposts=10');
   
       global $more;
       // set $more to 0 in order to only get the first part of the post
       $more = 0; 
   
       // the Loop
       while (have_posts()) : the_post();
       ?>
   
       		<?php if(is_category(12)) { ?>
       			<li <?php post_class() ?>>
                   		<div class="title">
   
               		<h2 id="post-<?php the_ID(); ?>">BLAH<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
   
               		<h3>Posted in: <span><?php the_category(', ') ?></span></h3>
   
               		</div> 
   
       			<!-- .post --></li>
   
       		<?php } else { ?>
   
       	         	<div class="title">
   
                               <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
   
                               <h3>Posted in: <span><?php the_category(', ') ?></span></h3>
   
                               </div> 
   
       		<?php } ?>
       ```
   
 * Right now I’d want it so that in the loop, if the category is 12, then print 
   the word “BLAH” ahead of the title (just as a test). Currently it’s not working.
   I have a feeling it’s because is_category checks to see if the entire PAGE is
   from a category, not just that specific post.
 * Any guidance is much appreciated.
 *  Thread Starter [greasypigstudios](https://wordpress.org/support/users/greasypigstudios/)
 * (@greasypigstudios)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/#post-1169551)
 * Ha, figured it out. It’s not
 * is_category
 * it should be
 * in_category
 * Fantastic. Good to have worked this out loud, and hopefully will help others 
   in future.

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

The topic ‘Same loop, different formatting depending on category?’ is closed to 
new replies.

 * 4 replies
 * 2 participants
 * Last reply from: [greasypigstudios](https://wordpress.org/support/users/greasypigstudios/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/same-loop-different-style-depending-on-category/#post-1169551)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
