12

I want to display some text on the last page that isn't displayed on the other pages.

For example, on category pages: url.com/category/categoryname/page/6

or last page of all posts listed on the homepage: url.com/page/9

How do I check if I'm on the last page?

Thanks in advance.

16

The WP_Query object contains a max_num_pages field which contains how many pages of posts there are. You can compare the current page number with it. (This is how get_next_posts_link() does it.)

global $wp_query;
$current_page = $wp_query->get( 'paged' );
if ( ! $current_page ) {
    $current_page = 1;
}
if ( $current_page == $wp_query->max_num_pages ) {
    // You are on the last page
}
1
  • 1
    Thanks for your help - I ended up using: <?php if ( $wp_query->max_num_pages == get_query_var('paged') ) : ?> <div>TEXT</div><?php endif; ?>
    – user7880
    Aug 17 '11 at 18:06
0

In short: If you want to learn more about pagination, I've written a Plugin for that.

In detail: You can take a look at the global $paged; global. But best would be to digg into the plugin code i linked and look at the render() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.