[resolved] newest post showing at top of every page (4 posts)

  1. wdawson
    Posted 5 years ago #

    OK, so I'm trying to have a page for each of my categories, but don't want to generate these pages with archive templates. Basically I just want it to be a list of all the posts from that category. Thing is I also want it paginated.

    I did this using query_posts, setting the category and the posts per page. I then added the next page links below this. Now what happens is the "next page" link takes me to a "paged=2" page but it displays the same thing as page 1.

    I just figured out I probably shouldn't be using query_posts for this, huh? What method would be recommended, get_posts? I checked the codex and can implement something else, just not sure what I should be using in the first place, or how to fix the current query_posts problem.

    Here's what I current have now (I know nopaging is set to true, I just did this for now, so disregard that):

    <?php query_posts('category_name=tcn-journal&posts_per_page=10&nopaging=true'); ?>
    					<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
    					<div class="fullpost">
    						<div class="text_col">
    							<div class="postdate_single">
    							[ <?php the_time('F j, Y') ?> ]
    							<div class="story_section_inside">
    							<?php echo get_post_meta($post->ID, "section", true);?>
    							<div class="posttitle_single">
    							<a href="<?php the_permalink(); ?>">
    							<?php the_title(); ?>
    							<div class="postcontent_single">
    							<?php the_excerpt(); ?>
    							<div class="moretext">
    							<a href="<?php the_permalink(); ?>">full story &raquo;</a>
    					<?php endwhile; ?>
    					<div class="post_nav">
    					<div class="moretext">
    					<?php previous_posts_link(); ?>
    					<span class="next_posts"><?php next_posts_link(); ?></span>
    					<?php endif; ?>

    Thanks so much.

  2. Christopher Spires
    Posted 5 years ago #

    Don't forget to add $query_string to your query, as follows:

    <?php query_posts($query_string.'category_name=tcn-journal&posts_per_page=10'); ?>
  3. Michael
    Forum Moderator
    Posted 5 years ago #

    for proper pagination, query_posts() needs the paged paramater:

    integrated into your query, for instance:

    <? $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts('category_name=tcn-journal&posts_per_page=10&nopaging=true&paged=' . $paged); ?>

    ( using $query_string in combination with a query might sometimes also work; http://codex.wordpress.org/Function_Reference/query_posts#Usage_Note )

  4. wdawson
    Posted 5 years ago #

    Ah yes, I just needed the paged parameter. Thanks a lot to both of you.

Topic Closed

This topic has been closed to new replies.

About this Topic