Jepson Center for the Arts

Get the Last Page of a Post in Wordpress

Here’s a quick function to determine whether or not the viewer is on the last page of a paginated post. It’s useful if you want to display information (comments, post meta, etc.) only on the last page.

While it’s possible to paginate long posts in Wordpress using the quicktag "<!--nextpage-->" and the template tag "wp_link_pages()", I needed a way to determine when the viewer was on the last page of the post.

The reasoning behind this was because I wanted comments and post meta information to be displayed only on the last page of the post. The default pagination of long posts results in this information being displayed at the bottom of every page of your post. Imagine a post with over 100+ comments, loading every time a viewer clicked on a page link. Not to mention aesthetics; showing redundant information over and over.

I looked through the WP Codex for information regarding pagination but didn’t find what I was looking for. A search in the majors (Google, Yahoo, MSN) returned few results as well. I thought I was going to have a write a specific database query to get what I was looking for, but scanning through the WP core (which I always review, but never mess with), I found a deceptively easy solution.

Continues…

Snapshot: Post

Posted: December 3rd, 2008

A quick function to determine whether or not the viewer is on the last page of a paginated post. It's useful if you want to display information (comments, post meta, etc.) only on the last page.

Disclaimer: While this script may come in handy for others, I designed it specifically for use on this site. I haven’t tested it in any version of Wordpress other than those that I’ve used (v2.6.3–v2.8.6). Feel free to use it if you’d like, but I make no guarantee it will work with your current theme or Wordpress setup. For a complete Copyright Notice and Disclaimer, visit the About Section of this site.

Topics

Or you can check out the full archive here: Article Archive.

Search