Support » Themes and Templates » Template Pagination WP_Query not working

  • Resolved afang22

    (@afang22)


    Hello,

    I have created a template for a page to display only posts from a specific category. Everything works except for the pagination. I have tried all the suggestions posted here and it still doesn’t work.

    Please help!

    Here is my code:

    <?php
    $cat = array(228);
    $do_not_show_stickies = 1; // 0 to show stickies
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

    $args=array(
    ‘category__in’ => $cat,
    ‘caller_get_posts’ => $do_not_show_stickies,
    ‘paged’ => $paged,
    ‘posts_per_page’ => 10,
    );

    $temp = $my_query;
    $my_query= null;
    $my_query = new WP_Query($args);
    ?>

    <?php if( $my_query->have_posts() ) : ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    ….

    <?php endwhile; ?>
    <?php $my_query = null; $my_query = $temp;?>

    <!– Previous/Next page navigation –>
    <?php next_posts_link(‘« Older Entries’) ?>
    <?php previous_posts_link(‘Newer Entries »’) ?>

    <?php else : ?>
    <h2>Not Found</h2>
    <?php endif; ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    the only ‘odd’ thing is that you reset the query before the next/prev posts links.

    <?php endwhile; ?>
    <?php $my_query = null; $my_query = $temp;?>
    
    <!-- Previous/Next page navigation -->
    <?php next_posts_link('« Older Entries') ?>
    <?php previous_posts_link('Newer Entries »') ?>

    i would try to do it after the endif;

    thanks. i tried moving it but it didn’t help. the only reason why i even included that $temp variable was because of another post i read.

    the problem is, the pagination buttons don’t even show up. it’s almost as it doesn’t know there are more posts to be displayed.

    Michael

    (@alchymyth)

    Forum Moderator

    have you got a link?

    you could also look into the html source in your browser to see if the html comment <!-- Previous/Next page navigation --> shows.
    you would know then, that the loop finished.

    yes, the <!– Previous/Next page navigation –> shows in the html source.

    the only thing i can think of is that i do have the page navigation plugin installed, but i am not calling the plugin function on my template.

    i’m using the default pagination, which i tested to make sure it works on the archive page.

    <?php next_posts_link(‘« Older Entries’) ?>
    <?php previous_posts_link(‘Newer Entries »’) ?>

    does it have anything to do with my WP_Query call. Should i be using query_posts instead?

    Michael

    (@alchymyth)

    Forum Moderator

    i can’t comment on this – so far, i have always used query_posts.

    did you try to deactivate the plugin, or call the plugin postnav function?

    in extreme, try deactivating all plugins, to see if that solves the problem.
    then reactivate them one-by-one, and see if the problem reoccurs.

    ah, i have identified the problem.

    i am using my own $my_query instead of the global $wp_query

    pagination only recognizes $wp_query

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Template Pagination WP_Query not working’ is closed to new replies.