• Resolved pcwebshop

    (@pcwebshop)


    Hi,

    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: https://pastebin.com/gy1zbT8t

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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>
     </div>
    Thread Starter pcwebshop

    (@pcwebshop)

    Thanks, works like a charm

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't get pagination to work on a custom loop’ is closed to new replies.