WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Archive Pagination with Total Pages (4 posts)

  1. ckruse
    Member
    Posted 5 years ago #

    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!

  2. ckruse
    Member
    Posted 5 years ago #

    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')));
    ?>

  3. phonglong
    Member
    Posted 4 years ago #

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

    http://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()
  4. Tammy Hart
    Member
    Posted 4 years ago #

    ckruse,

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

Topic Closed

This topic has been closed to new replies.

About this Topic