Support » Plugins » Hacks » Show two post from one category

  • Hi,

    I need to show two post from one category for a news feed. I know it needs to go in the query_posts () but I’m not sure exactly how to go about it.

    Would appreciate any help, thanks.
    Kieran

Viewing 4 replies - 1 through 4 (of 4 total)
  • try this:

    <?php
    
    query_posts( array(      'posts_per_page' => 2,      'cat' => '1',     'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ), ));?>
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <h4 class="posttitle"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e( 'Permanent Link to', 'cc' ) ?> <?php the_title_attribute(); ?>"> <?php the_title(); ?> </a></h4>
    
    <small><?php the_category(); ?> </small>
    <?php endwhile; ?> 
    
    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', '' ) ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', '' ) ); ?></div>
    
    <?php endif; ?> </br></br>
    <?php wp_reset_query();?>

    no need to reset the entire query. just use wp_reset_postdata()

    Exactly what i needed… Thank you for this 🙂

    Thanks for that mark, still not clear on the difference, in a nut shell, what are the advantages, disadvantages of reseting the query vs. using post reset?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show two post from one category’ is closed to new replies.