• Resolved ckruse

    (@ckruse)


    I have figured out ways to implement pagination on my own using a second query to get a total, but I can not figure out how to do it on an archive page, where you could be view a category, month, year, etc.

    I have a pagination system set up, but what I need is a way to display the total pages. For example:

    << Page 3 of 11 >>

    Obviously all I really need is a variable of some kind that tells me what the total number of pages are.

    Thanks for any help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter ckruse

    (@ckruse)

    I figured it out. I must be getting smarter. In case anyone else needs this. It actually works great for all pages

    <?php
    //set up for paging
    if($paged == 0 || $paged == “”) { $paged = 1; }

    //get the SQL statement which was run.

    $theQuery = $wp_query->request;
    //need to remove the limit
    $theQuery = substr_replace($theQuery, “”, strpos($theQuery, “LIMIT”), strlen($theQuery));
    //now run the query again
    $get_max_pages = $wpdb->query($theQuery);
    $max_pages = ceil(($get_max_pages)/(get_option(‘posts_per_page’)));
    ?>

    if you’re using wordpress 2.5+, you can use the built in post/category/tag/etc counting functions:

    https://wpengineer.com/show-amount-of-posts-pages-categories-tags-comments-for-wordpress-themes/

    in case the link dies, here’s a summary of function:

    wp_count_posts()
    wp_count_terms()
    get_comment_count()
    wp_count_comments()

    ckruse,

    Thanks for that bit of code, just what I needed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Archive Pagination with Total Pages’ is closed to new replies.