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 →

Move a comment to another post

October 21, 2008

Even if this is quite rare, it happen sometimes that someone leave a comment on a post instead of another one. In that case, it is possible to move the comment by using phpmyadmin and sql. First of it all, login to your phpmyadmin and choose your WordPress database. Once done, click on the sql button to open the sql command window. Now, we have to get the ID of each post. Once you have it, run the following command on the SQL window: UPDATE wp_comments SET comment_post_ID=NEW_ID WHERE comment_post_ID=OLD_ID; Right now, the... [Read the full story]

Provide rss feed for each post comments

October 21, 2008

When a post have lots and lots of comment, it can be hard for your readers to stay on the conversation. Most WordPress users don’t know it, but our favorite blogging engine have a built-in function for providing rss feed for the comments of a specific post. Well, this recipe isn’t really a hack or anything: Even if most WordPress users seems to ignore it, in order to provide a rss feed for the comments of specific post, you just have to call the comment_rss_link() function: <?php comments_rss_link('» Comments RSS... [Read the full story]

Display comments and trackbacks separately

October 19, 2008

When you’re reading comments on a blog post, trackbacks are annoying. It’s way better to display it separately from comments. Open and edit the comments.php file from your theme. Find the comment loop: foreach ($comments as $comment) : ?> // Comments are displayed here endforeach; Replace it with the following: <ul class="commentlist"> <?php //Displays comments only foreach ($comments as $comment) : ?> <?php $comment_type = get_comment_type(); ?> <?php if($comment_type... [Read the full story]

Reverse WordPress comments order

October 19, 2008

For those who knows at least a bit of the php programming language, you probably already heard about the array_reverse() function. This function takes an array as argument, and return it reversed. Just open the comments.php file from your theme. Find the following line: <?php foreach ($comments as $comment) : ?> Now, add this line below: <?php $comments = array_reverse($comments, true); ?> The code should look like this: <?php $comments = array_reverse($comments, true); ?> <?php foreach ($comments as... [Read the full story]