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.
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
}