[resolved] Can't get pagination to work on a custom loop (3 posts)

  1. pcwebshop
    Posted 2 years ago #


    I have a site that pulls in posts on pages based on the category id, as found in a custom field, due to multiple pages using one template.
    I need to add pagination to the loop, but everytime I have tried, I get a white screen. The code I have developed from bits and pieces found on the internet. Coding like this is not one of my strenghts so any help would be appreciated.

    See code here: http://pastebin.com/gy1zbT8t

  2. vtxyzzy
    Posted 2 years ago #

    I believe that this will add the pagination to the query itself:

    $paged = (get_query_var('paged')) ? get_query_var('paged') :
                ((get_query_var('page')) ? get_query_var('page') : 1);
    $args = array(
       'cat' => $toptracks,
       'posts_per_page' => 3,
       'paged' => $paged,
    $the_query = new WP_Query($args); ?>

    You will still need to add the code to actually show the pagination. It usually looks something like this:

    <div class="navigation">
       <div class="alignleft"><?php next_posts_link('&laquo; Older Entries', $the_query->max_num_pages) ?></div>
       <div class="alignright"><?php previous_posts_link('Newer Entries &raquo;', $the_query->max_num_pages) ?></div>
  3. pcwebshop
    Posted 2 years ago #

    Thanks, works like a charm

Topic Closed

This topic has been closed to new replies.

About this Topic