• I have one particular category of post that I want to exclude from the home page, and show by itself on its own “Daily Specials” page. So I used query_posts to exclude it

    <?php global $query_string; // required
    	$posts = query_posts($query_string.'&cat=-8'); // exclude category 8
    ?>

    …and that worked just fine. No Daily Specials in the main blog stream. Then I set up a separate page, and on that template I included

    <?php global $query_string; // required
    	$posts = query_posts($query_string.'&cat=8'); // limit to category 8
    ?>

    The loop is the same used on the home page (except that it excludes permalinks and meta information, since I don’t want separate pages for these posts). The problem is: the posts aren’t showing up. The date is; but the title and content is missing.

    This is the full code for the specials page:

    <?php global $query_string; // required
    	$posts = query_posts($query_string.'&cat=8'); // limit to category 8
    ?>
    
    	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post" id="post-<?php the_ID(); ?>">
    
    			<div class="entry-meta">
    				<p class="entry-date"><?php the_time('F')?><br /><span class="date"><?php the_time('j')?></span></p>
    			</div><!-- .entry-meta -->
    
    		<h2 class="entry-title"><?php the_title(); ?></h2>
    
    		<div class="entry-content">
    			<div class="entry">
    				<?php the_content(); ?>
    			</div>
    		</div>
    
    	</div>
    
    <?php endwhile; ?>
    
    <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    
    <?php else : ?>
    
    	<h2>Not Found</h2>
    
    <?php endif; ?>
    
    <?php wp_reset_query(); // reset the query ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • in a page template, use for instance:

    <?php query_posts('post_type=post&cat=8&paged='.get_query_var('paged')); // limit to category 8
    ?>
    Thread Starter Who_Dat

    (@who_dat)

    Thank you, that worked.

    Since the home page is also loading from a template (home.php), should the code on that page follow the same pattern? i.e.:

    <?php query_posts('post_type=post&cat=-8&paged='.get_query_var('paged')); // exclude category 8
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limiting posts to one category: posts not showing up’ is closed to new replies.