WordPress CMS modifications

Making WordPress more like a CMS everyday!





How to show the total number of posts, categories and tags - maybe in your sidebar

Last Modified: 24 July, 2008 (17:22) | First Created: 26 January, 2008
Posted In: Code Customisation | Written by: Jonny

It is easy to get WordPress to show the total number of posts, categories and tags - some people like to show this in their sidebar or footer.

Just paste this code into your sidebar or footer template, and obviously style as wished.

<?php
$numposts = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
$numcomms = (int) $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'");
$numcats = wp_count_terms('category');
$numtags = wp_count_terms('post_tag');
?>
<p><?php echo 'There are currently ' . $numposts . ' posts' . ', contained within ' . $numcats . ' categories' . ', using ' . $numtags . ' tags.';?></p>


Write a comment