WordPress Posts Pagination

I recently had to find a way of forcing WordPress to display a post that had been paginated using the nextpage quicktag, to display different content on different dynamically generated pages. After some help from StackOverflow.com I found out that within The Loop you can access 2 particular variables that WordPress uses: $page and $numpages.

Without having to be a genius $page is the current page number and $numpages is the total number of pages that a post has been converted into by WordPress.

Example: To have something appear only on the first page of a paginated post use:

if($page == 1 || $numpages == 1) {
	//will only appear on first page
}

Example: To have something appear only on the last page of a paginated post use:

if($page == $numpages) {
	//will only appear on last page
}
blog comments powered by Disqus