views:

40

answers:

1

A few things to understand before my question will make sense:

  • I use a hidden category called 'Unique' to specify if the post will use the single.php or a special one used for the unique ones.
  • I want the index to act as a single: showing only one post, displaying next/prev post links, and comments also.
  • I need the index.php to say if the post is in category 15 (unique) than <the_unique_content>, else; <the_default_content>

My loop does all this, but the problem is that if the current post is unique, it also displays 1 additional post below the unique post.

Here is the loop >

<?php $wp_query->is_single = true; ?>

<?php $post_count = 0; ?>

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>    

    <?php if ($post_count == 0) : ?>

<?php if (in_category('15')) { ?>   

<?php the_content(); ?> 

<?php } else { ?> 



 <?php the_content(); ?>    



    <?php $post_count++; ?>

Thanks for any help!

A: 

I don't think you are setting the query correctly to return a single post. Your code is limiting the number of posts through your $post_count variable, but in the case where the post is "unique", it only increments to 1 on the second post.

Here is one way to limit the number of posts to a single post. It involves modifying the loop query to set the number of posts per page to one.

<?php
global $wp_query;

$new_query = array_merge( array( 'posts_per_page' => 1 ), $wp_query->query );

query_posts( $new_query );

if (have_posts()) : while (have_posts()) : the_post(); ?>

etc...

Greg