Display a text or code only if more than X posts are published

February 1, 2009 · Print This Article

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

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

Your choice for site templates and wordpress themes


Got something to say?

You must be logged in to post a comment.