Forums

[Plugin: WP-Paginate] WP_Query paginate (5 posts)

  1. dkblackhawk
    Member
    Posted 2 years ago #

    How would I go about paginating this?
    <?php $recent = new WP_Query('cat=1,35,32,27,42,37,3,8,4,7,26,36,6,5'); while($recent->have_posts()) : $recent->the_post();?>

    Whenever I click on a different page other than page 1, the posts just stay the same.

    Please help. Thanks :)

    http://wordpress.org/extend/plugins/wp-paginate/

  2. Eric Martin
    Member
    Posted 2 years ago #

    You need to add logic to include the page in the query.

    For example:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $recent = new WP_Query("cat=1,35,32,27,42,37,3,8,4,7,26,36,6,5&paged=$paged");

    Hope that helps.

  3. bbacarat
    Member
    Posted 2 years ago #

    I think this post is related to a problem I'm suffering with also. In your second line of code

    $recent = new WP_Query("cat=1,35,32,27,42,37,3,8,4,7,26,36,6,5&paged=$paged");

    Are pages dynamically added to this list of page/post numbers or do you have to add them manually?

    Oh and where am I supposed to place this code?

    Also I've had the same problem with another Pagination plugin so I believe it might be something to do with my folder permissions. What does your plugin require on that front to be able to work correctly?

  4. dkblackhawk
    Member
    Posted 2 years ago #

    I'll share you the code that got it working for me :)

    <?php
    $temp = $recent;
    $recent= null;
    $recent = new WP_Query('cat=-6&showposts=5&paged=' . $paged);
    while ($recent->have_posts()) : $recent->the_post();
    ?>
    
    Template to view the posts itself
    
    <?php
    if(function_exists('wp_paginate')) { wp_paginate(); }
    $recent = null; $recent = $temp; ?>

    Also, I have just fixed my other problem when it was showing empty pages. You have to remove the "cat=-6&" from WP_Query. Then you should have no blank pages like I did.

    Hope it helps!

  5. empek
    Member
    Posted 1 year ago #

    EDIT:

    Nevermind,

    I started from scratch following this tutorial and got it working.

    Good article to read if you're having the same issue.

Topic Closed

This topic has been closed to new replies.

About this Topic