Display the total number of users of WordPress
April 29, 2009
If your wordpress allow user registration, what about displaying the total number of registered users? This simple code will allow you to do it easily. Simply paste the following code anywhere in your wordpress theme files: $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users." registered users."; Once you saved the file and refreshed your wordpress, the total number of users will be displayed. Read More →
Number your wordpress comments
February 3, 2009
Do your blog posts receive lots of comments? If yes, it can be really useful for both you and your readers to number it. Here’s how to do it easily and efficiently. Open comments.php and find the following line: <?php foreach ($comments as $comment) : ?> Just below this line, initialize a counter variable: <?php $i = 0; ?> Just after this line, increment the counter: <?php $i++; ?> Now, you just have to echo the $i variable to get the number of the current comment. Paste this code anywhere on your comments... [Read the full story]
Display the number of comments on each wordpress post
December 16, 2008
How we can display the number of comments for each posts? While some themes do it by default, most of them don’t display it at all. To solve this problem, simply open your index.php file and paste the following code within the loop: <?php comments_number('No comments yet','1 comment','% comments')?> Even better, following code have a link to jump directly to the comments: <a href="<?php the_permalink() ?>#comments"><?php comments_number('No comments yet','1 comment','% comments')?></a> Read More →
Display the total number of comments on your WordPress
October 21, 2008
This simple hack works exactly as the “get total number of posts” hack works: We’re using the $wpdb object and make a custom query to MySQL: $numcomms = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_approved = '1'"); if (0 < $numcomms) $numcomms = number_format($numcomms); Right now, the $numcomms variable contains the total number of comments posted on your WordPress blog. To display this number, simply do something like: <?php echo "There's ".$numcomms." comments on this blog"; Read More →
Display the total number of posts on your WordPress
October 20, 2008
Wouldn’t it be nice to be able to display the total number of posts published on your WordPress blog? WordPress don’t have a function to do that by default, but happilly this hack is here to help. Here’s the code: We’re using the $wpdb object to make a custom query to WordPress database: $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'"); if (0 < $numposts) $numposts = number_format($numposts); Right now, the $numposts variable contains the total number of posts.... [Read the full story]



















