Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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; ?> See it here, if you're interested :) [link]muchzen.com/category/topic/inspiring-quotes/page/10 –  user7880 Aug 17 '11 at 18:06
add comment

Your Answer

 
discard

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.