views:

616

answers:

1

I have a permalink structure of /%catergory%/%postname%/.

When I go to blah.com/categoryname I want all posts in that specific category to be listed. When I go to blah.com/categoryname/post-name I want just the specific post to be displayed.

I have made a category specific template (category-5.php) and have got as far as...

// Display all post titles in category loop
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<?php endwhile; ?>
<?php endif; ?>

// Display specific post in category loop
<?php if ( have_posts() ) : the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <div class="storycontent">
        <?php the_content(); ?>
    </div>
<?php endif; ?>

...but obviously I only want the first loop to display when the url is blah.com/categoryname, and the second loop to display when the url is blah.com/categoryname/post-name.

Any thoughts? thanks

A: 

You can't have two loops running on the same page as you do here.

I believe you need to separate out the two things you're trying to do. To have a unique look/feel for the category, create a category-1.php file. To create a unique look/feel for the posts within that category, create a separate 'single' template.

This WP support thread explains how to create the 'single' template: http://wordpress.org/support/topic/266638

There are also a few "post template" plugins that help accomplish the same thing, if you prefer to go that route, for instance: http://wordpress.org/extend/plugins/post-template/

Full list here: http://wordpress.org/extend/plugins/search.php?q=post+templates

Good luck!

McGirl
Thanks for the tips. There was a problem though with using a category-1.php template along with a single.php template. The category-1.php template always overrode the single.php. I could well have done something wrong though. I worked out another method of getting the right result...I wrapped the first loop with an 'if (!is_single())' and the second loop with an 'if (is_single())'.
Jack