[resolved] Paginating Posts (3 posts)

  1. dannelson
    Posted 4 years ago #

    Need to show posts within a specific category and paginate. Pagination appears and is able to identify the correct amount of posts, but when moving from New to Old entries, the posts do not change. The URL changes correctly (...page/2/) but the same posts appear. Tried a variety of ways yet no solution seems to work.

    Template Name: Page-Blog
    get_header(); ?>
    	<h1><?php the_title(); ?></h1>
    	<?php get_sidebar(); ?>
    	<?php query_posts('cat=4&posts_per_page='.get_option('posts_per_page')); ?>
    		<?php if (have_posts()) : ?>
    			<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
    			<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    			<ul id="blog-posts">
    				<?php while (have_posts()) : the_post(); ?>
    						<div id="two-column">
    							<div <?php post_class() ?>>
    								<div class="entry">
    									<?php the_content(); ?>
    						<?php include (TEMPLATEPATH . '/sidebar-blog.php' ); ?>
    				<?php endwhile; ?>
    			<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>
    	<?php else : ?>
    		<h2>Nothing found</h2>
    	<?php endif; ?>
    <?php get_footer(); ?>
  2. Big Bagel
    Posted 4 years ago #

    Add the 'paged' parameter to your query:

    <?php query_posts( 'cat=4&posts_per_page=' . get_option( 'posts_per_page' ) . '&paged=' . get_query_var( 'paged' ) ); ?>

  3. dannelson
    Posted 4 years ago #

    Thanks Big Bagel. Appreciate the help.

Topic Closed

This topic has been closed to new replies.

About this Topic