WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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
share|improve this answer
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

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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