Title: Display posts in diff template layouts using loop within a loop
Last modified: August 19, 2016

---

# Display posts in diff template layouts using loop within a loop

 *  [irishmark](https://wordpress.org/support/users/irishmark/)
 * (@irishmark)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/display-posts-in-diff-template-layouts-using-loop-within-a-loop/)
 * I want tmy theme to deiplay each post in a certain way depending on he catagory.
   The reason for this is I use the site to display my twitter updates too. Thisresults
   in lots of updates. So i want to make the twitter posts smaller than normal posts.
 * This is how the site displays posts at the moment:
    [Current Look](http://www.irishmark.net/MEDIA//2009/05/im-dev.jpg)
 * This is what it should look like:
    [New Look](http://www.irishmark.net/MEDIA//2009/05/im-devnew.jpg)
 * I appreciate that itb will involve some CSS but i ill deal with that once i have
   the Loop sorted. This is the code so far but it dosn’t work. I think i need to
   create a loop within the main loop.
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
   
       			<?php $post = $wp_query->post;
             if ( in_category('28') ) {
             include(TEMPLATEPATH . '/tweet_cat.php’);
             } else {
             include(TEMPLATEPATH . '/cat.php');
             } ? >	
   
       			<?php endwhile; else: ?>
   
       			<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
       			<p><?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?></p>
       ```
   
 * tweet_cat.php and cat.php are 2 simple files displaying the relevant tags in 
   the order they should be arranged in for the diffrent catagories.
 * I just don’t know how to code it to do this nor do i know if it’s beyond WP capabilities.

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

 *  [Nathan Rice](https://wordpress.org/support/users/nathanrice/)
 * (@nathanrice)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/display-posts-in-diff-template-layouts-using-loop-within-a-loop/#post-1100597)
 * This should work:
 *     ```
       <?php if(have_posts()) : while(have_posts()): the_post(); ?>
   
       <?php
       if(in_category('28')) {
       	include(TEMPLATEPATH . '/tweet_cat.php’);
       } else {
       	include(TEMPLATEPATH . '/cat.php’);
       }
       ?>
   
       <?php endwhile; else : ?>
   
       <p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
       <p><?php posts_nav_link(' — ', __('&laquo; Previous Page'), __('Next Page &raquo;')); ?></p>
   
       <?php endif; ?>
       ```
   
 * Notice I took a couple of things out that were unnecessary (like defining the
   $post varialbe. the_post() function already does that).
 * The only variables are the 2 files you’re pulling in. If they contain new loops,
   and not just in-loop template tags, then it could screw some things up. If the
   code I gave you above doesn’t work, then the problem is in those 2 files somewhere.
 *  Thread Starter [irishmark](https://wordpress.org/support/users/irishmark/)
 * (@irishmark)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/display-posts-in-diff-template-layouts-using-loop-within-a-loop/#post-1100932)
 * That does work but it doesn’t achieve what i want
 * I want to be able to use diffrent templates on the **same **page

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

The topic ‘Display posts in diff template layouts using loop within a loop’ is closed
to new replies.

## Tags

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

 * 2 replies
 * 2 participants
 * Last reply from: [irishmark](https://wordpress.org/support/users/irishmark/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/display-posts-in-diff-template-layouts-using-loop-within-a-loop/#post-1100932)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
