WordPress: more_posts, old_posts, new_posts

January 24, 2007

I just scratched an itch I’ve had for a long time. I always hate how on my category pages and my archive pages the little “More Posts” box would display even if there were no posts. Also, I could never check and see if there were no “Newer” or no “Older” posts so I could still print the words out in non-link form.

I finally did something about it today. I started by looking through the codex, and finding nothing. So I started digging through the WP code looking for the posts_nav_link() which sorta did what I wanted, but just echoed to the page instead of returning. I found it in wp-includes/template-functions-links.php and started chopping it up.

In the end I came up with three functions for my ‘my-hacks.php’ file. I didn’t want to spend the time making it into a plugin since it’s not that big a deal. They aren’t terribly efficient, but they work and thats what matters. Also, I pre-pended jh to the function names so there wouldn’t be any chance of collisions.

Returns true if there are more posts, newer or older.

Returns true if there are more ‘older’ posts.

Returns true if there are more ‘newer’ posts.

Categories: Geek
Tags: , , ,

Leave A Comment

Your email will not be published.