Full Subscription Options:
RSS for The Newsroom | RSS for Comments from The Newsroom
Alternatively, you may also want to subscribe to some of our other RSS feeds, such as:
Would you like to test drive one of our themes before deciding whether or not you like it...?
Would you like to have your own free blog that we will host for you and you can use for anything...?
If the answer to either of these questions is yes, CLICK HERE to start the sign-up process!
|
This nifty little hack will display a post and comment count and can be easily edited, but basically, all you need to do is paste the following code into your PHP file where you want the sentence displayed:
<?php
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); echo $numposts.' articles have been published on this site,'; echo " sharing a total of ".$numcomms." comments."; ?> This will display XX articles have been published on this site, sharing a total of XX comments, and will only work correctly with Wordpress - if used with MU, it will only display the number of posts and comments specifically for the blog it is seen from… If you want to define the variables in one place and then re-use the stats as numbers on their own (so they can be better styled) all you need to do is split the code as follows - by first defining the variables:
<?php
$numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); ?> Then call the numbers using either of the following:
<?php echo $numposts // Is the number of posts ?>
<?php echo $numcomms // Is the number of comments ?> Read More From The WP Hacks Category
No Responses to “Display Post & Comment Count”
|