• Hello,

    I’ve created a news page on my WordPress 3.3 website. I want to display only posts that are created using the “news” category on this page.

    I was using this code, but it pulls in all posts, no matter what category they are tagged in:

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

    I have tried using this in my code:

    <?php query_posts($query_string . '&cat=4'); ?>

    But I don’t think I’m querying posts correctly. It looks like the news page I made is only querying the content from that specific page. I would like this page to act like the homepage when I set the posts page to a specific page (I have already done that for a page called Blog).

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not so hot with this stuff but this works for me in a php widget, not exactly sure how to use it in a page template but you might play around with it. You can see where to enter the cat id and number of posts.

    <div id="list-posts">
    	<?php
    	global $post;
    	query_posts('cat=1&posts_per_page=5');?>
    	<?php if ( have_posts() ) : ?>
    	<?php while (have_posts()) : the_post(); ?>
    					<div class="entry">
    				<?php the_content();?>
    			</div>
    
    	<?php endwhile; ?>
    	<?php else : ?>
    
    	<?php endif; ?>
    	<?php wp_reset_query();?>
    </div>

    It’s probably more than you need for what you’re doing, but no one else has assited so I figured it’s something to try.

    You could also use a custom menu and link news to the category. No coding required.

    Thread Starter foochuck

    (@foochuck)

    @swansonphotos – good call. I should’ve thought of that…hehe. Thanks!

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

The topic ‘Display Posts from a Specific Category Only’ is closed to new replies.