WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. pcwebshop
    Member
    Posted 11 months ago #

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

  2. vtxyzzy
    Member
    Posted 11 months 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>
     </div>
  3. pcwebshop
    Member
    Posted 11 months ago #

    Thanks, works like a charm

Reply

You must log in to post.

About this Topic