Proper Singulars for Blog Stats

By Richard X. Thripp at 2008-07-05T18:21:34Z in News, with these tags: blogs, stats, jump to comment form. 144 words.

If you sign up for a blog, before it would say in your stats in your sidebar:

1 Posts
1 Pages
1 Comments

Now it says:

1 Post
1 Page
1 Comment

And those change to plural once you rise above one. Hacked up this conditional code for it (Wordpress MU):

<strong>Stats for <a href=”<?php bloginfo(’url’); ?>/”>this blog</a>:</strong><br />

<?php echo $countposts = $wpdb->get_var(”SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘post’”);
if ($countposts == ‘1′) echo ” Post”;
else echo ” Posts”; ?><br />

<?php echo $countpages = $wpdb->get_var(”SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘page’”);
if ($countpages == ‘1′) echo ” Page”;
else echo ” Pages”; ?><br />

<?php echo $countcomments = $wpdb->get_var(”SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = ‘1′”);
if ($countcomments == ‘1′) echo ” Comment”;
else echo ” Comments”; ?><br />

Not the most efficient way, but it gets the job done, which is what counts. thripp.com just got a bit smarter.




Have no fear — commenting is here. Comments RSS feed.

These HTML tags work: a href, abbr, acronym, b, blockquote, code, em, i, strike, strong, u. You will be emailed if anyone replies to your comment. Gravatars work here. Thanks for commenting!