Support » Fixing WordPress » Query posts page navigation problem

  • Resolved HappyCloud


    I’m having some trouble with a theme I am developing.

    It’s a basic CMS with a small blog.

    I have created a custom page template that queries only posts that are in the ‘blog’ category which works perfectly, but when more than the set amount of posts per page (In this case, 10) and the WP Page numbers plugin appears, each blog page is full of the same posts.

    Here is the code below, I would be most appreciative if anyone could help.

    Thanks in advance

    <div class="blog-wrap">
            <?php $posts = query_posts('category_name=blog'); if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div class="blog-post">
    				<div class="blog-title">
                    	<div class="date">
                        	<?php the_date('M', '<h4>', '</h4>'); ?>
                            <h4><span><?php the_time('d'); ?></span></h4>
                        </div><!-- .date -->
                        <h5><a href="<?php the_permalink(''); ?>"><?php the_title(''); ?></a></h5>
                        <p class="blog-meta">Posted under : <?php the_category(' '); ?> & tagged with <?php the_tags('',' - '); ?></p>
                    </div><!-- .blog-title -->
                    <div class="blog-content">
                    	<a href="<?php the_permalink(''); ?>"><img src="<?php bloginfo('url'); ?>/wp-content/content/blog/<?php echo get_post_meta($post->ID, "blog-thumb", $single = true); ?>.jpg" alt="<?php the_title(''); ?> image" title="<?php the_title(''); ?>"></a>
                        <?php the_excerpt(''); ?>
                        <p class="read-more"><a href="<?php the_permalink('');?>">Click here to read the rest of this entry >>></a></p>
                        <div class="clear"></div><!-- .clear -->
                    </div><!-- .blog-content -->
    			</div><!-- .blog-post -->
                <?php if(function_exists('wp_page_numbers')) { wp_page_numbers(); } ?>
    		<?php endwhile; ?>
    		<?php else : ?>
    		<?php endif; ?>
        </div><!-- .blog-wrap -->
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must include the ‘paged’ argument to your query:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $posts = query_posts("category_name=blog&paged=$paged"); if (have_posts()) : while (have_posts()) : the_post(); ?>

    Thanks man, worked perfectly

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query posts page navigation problem’ is closed to new replies.