Support » Themes and Templates » Page Pagination Not Working with Pages

  • Resolved hollywoodgrind

    (@hollywoodgrind)


    I am using a Page with a custom template that uses the following code to create a loop of 5 posts per page, which are paginated:

    <?php query_posts(array('category__and'=>array(18),'showposts'=>5)); ?>
    <?php while(have_posts()) : the_post(); ?>

    The problem is, page 2, page 3, etc., continue to show posts 1-5, and not 6-10, 11-15, etc. The loop just keeps repeating posts 1-5. The category contain 190 posts.

    Here’s the page:
    http://www.nerdgrind.com/tech-and-gadgets-news/

    I even tried adding ‘posts_per_page=’=>5 to the options, but the results are the same.

    Does anyone know what the problem could be?

Viewing 7 replies - 1 through 7 (of 7 total)
  • See my comments here on the topic:

    http://wordpress.org/support/topic/152451#post-679318

    Thank you very much Kafkaesqui, you solved my problem.

    I modified this a bit to limit the number of posts per page to 5, and also specified a single category to query posts from. Here is the code I used. Maybe it will help the next person.

    <?php
    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=12&showposts=' . $limit=5 . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;
    ?>

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

    <!--Do Stuff Here-->

    <?php endwhile; ?>

    have not try this yet.. but im using custom query from moshu for this.

    What if the trigger was the Tags? how to wrote it down?
    thanks..:)

    Thank you! I have the same problem like you, and now resolved. haha

    For some reason it’s not working for me. I’m using

    <?php
    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=8&showposts=' . $limit=6 . '&paged=' . $paged);
    $wp_query->is_archive = true; $wp_query->is_home = false;
    ?> 
    
    <?php if (have_posts()) { ?>
    
    		<div class="navigation">
    			<?php posts_nav_link(' · ', 'previous page', 'next page'); ?>
    		</div>
    
        <?php $i = 1; ?>
    
        <?php while (have_posts()) { the_post(); ?>
    		<?php //if (in_category('8')) { ?>
            <?php if ($i == 1) { ?>
    
    			<?php include TEMPLATEPATH . '/includes/focus.php'; ?>
    
            <?php } else { ?>
    
                <?php include TEMPLATEPATH . '/includes/posts.php'; ?>
    
            <?php } ?>
    
            <?php $i++; ?>
    
        <?php }//} ?>
    
    		<div class="navigation">
    			<?php posts_nav_link(' · ', 'previous page', 'next page'); ?>
    		</div>
    
    <?php } else { ?>
    
        <?php include TEMPLATEPATH . '/includes/error.php'; ?>
    
    <?php } ?>
    
    </div><!-- /home -->

    The front page works as expected, but the “paged” results are returning 404 errors. Any ideas as to what could be the culprit?

    Adam

    This tutorial did the trick. Perfect!

    The weblogtoolscollection tutorial above shows all articles on the site, from all categories, with paging on a specific Page, but doesn’t allow you to specify the articles to come from a specific category. You can get the same result on the homepage.

    On NerdGrind we needed a Page that would show all articles from a specific category, or multiple specific categories, not all categories, and for those articles to be paged on the Page. You can see the result using the link below.

    http://www.nerdgrind.com/tech-and-gadgets-news/

    I posted the code above when this thread started, but I had to slightly modify it to work with the latest version of WordPress. The code that changed was is_archive to is_category. The working code is shown below:

    <?php
    global $more;
    // set $more to 0 in order to only get the first part of the post
    $more = 0;
    $limit = get_option('posts_per_page');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=12&showposts=' . $limit=5 . '&paged=' . $paged);
    $wp_query->is_category = true; $wp_query->is_home = false;
    ?>
    
    <?php while (have_posts()) : the_post(); ?>

    On NerdGrind we plan to start doing WordPress tutorials soon which will be found in the http://www.nerdgrind.com/latest-how-tos/ section.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Page Pagination Not Working with Pages’ is closed to new replies.