DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

On Cats Who Code, I shown you how to integrate a pagination on your theme. That’s a nice trick, but if you styled it with css and have less than 11 posts published, it will only display a blank container. Let’s fix it.

To achieve this recipe, we’re going to use a cool new function, introduced in WordPress 2.7, and called wp_count_posts().

Paste the following code anywhere on your template:

$count_posts = wp_count_posts();
if ($count_posts->publish > 10) {
    //Your code to be displayed only if more than ten posts have been published

That’s all. Note that you’ll need to replace 10 by the number of posts which are displayed at the same time on your homepage.

Leave a Comment

Your email address will not be published. Required fields are marked *