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]

Add a edit link on each post

October 21, 2008

Sometimes, you read one of your blog post and you see a typo or an error. Sure, you got to correct it. But who said you must open your WordPress dashboard, go to “Manage” and then edit the post? In this recipe, I’m going to show you how to add a button to allow the admin to directly edit the post. To achieve this recipe, we need the current_user_can() WordPress function. This function checks the given parameter, which is the level of the current user, and returns true if the level of the current user is superior or... [Read the full story]

Insert Adsense after the first post

October 21, 2008

This seems to be a common WordPress question, but implementing it on your theme isn’t hard at all. The only thing we need is a simple php variable (here named $count) which will count how many posts are listed. If we just listed the first post, we’ll display the Adsense code. Here’s the code. Paste it on your index.php file, instead of your current WP loop. <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count <... [Read the full story]

Page 5 of 9« First...«34567»...Last »