WordPress.org

Ready to get started?Download WordPress

Forums

Display posts in diff template layouts using loop within a loop (3 posts)

  1. irishmark
    Member
    Posted 5 years ago #

    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

    This is what it should look like:
    New Look

    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.

  2. nathanrice
    Member
    Posted 5 years ago #

    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.

  3. irishmark
    Member
    Posted 4 years ago #

    That does work but it doesn't achieve what i want

    I want to be able to use diffrent templates on the same page

Topic Closed

This topic has been closed to new replies.

About this Topic