Make your comments template compatible with WordPress 2.7 and older versions

November 11, 2008

You’ll need two file: The first one is a WordPress 2.7 compatible comments file, named comments.php. The second one is a comment template for older WordPress versions, named legacy.comments.php in this exemple. Paste this elegant code in your theme functions.php file. Create this file if it do not exists yet. If the wp_list_comments() function doesn’t exists, the code will automatically load legacy.comments.php instead of comments.php. <?php add_filter('comments_template', 'legacy_comments'); function legacy_comments($file)... [Read the full story]

Alternate background color in wordpress comments list

November 11, 2008

If you have a large amount of comments on your blog, it can be very more readable to alternate background colors. Edit the comments.php file from your theme. First, find the following line: <?php if ( $comments ) : ?> Once you found it, replace the comment loop by the following code: <ul> <?php $i = 0; ?> <?php foreach ($comments as $comment) : ?> <?php $i++; ?> <li id="comment-<?php comment_ID() ?>" <?php if($i&1) { echo 'class="odd"'; } else { ... [Read the full story]

Make comments section WordPress 2.7 compatible

November 8, 2008

Here’s a basic comments loop for WordPress 2.7. You just have to replace your current comment loop with that one to make it work with WordPress 2.7. <?php if (have_comments()) : ?> <h4 id="comments"><?php comments_number('No Comments', 'One Comment', '% Comments' );?></h4> <ul class="commentlist"> <?php wp_list_comments(); ?> </ul> <div class="navigation"> <div class="alignleft"><?php previous_comments_link() ?></div> <div class="alignright"><?php... [Read the full story]

Get rid of the comment section on your WordPress blog

October 24, 2008

Altought it can be weird in some points because comments are an important part of a blog, I have read many user asking how they can get rid of the “comments” section on their WordPress theme. That’s very easy to do. Removing the comments section on a blog can sound weird at first, but sometimes you just want to spread some news without getting any feedback. In case you don’t want any post to be commented, just edit your single.php file from your theme. Find the following line: <?php comments_template(); ?> and... [Read the full story]

Get most commented posts of the week

October 22, 2008

To achieve this hack, we have to make a custom SQL query by using the $wpdb object. Let’s start by creating 3 php variables: The first one is the number of days between today and X days ago, the second is today’s date and the last one is today’s date – X days. <?php $days = 7; //To fetch posts published during the last 7 days $today = date("Y-m-d H:i:s"); //Today's date $daysago = date("Y-m-d H:i:s",strtotime(date('Y-m-j H:i:s')) - (7 * 24 * 60 * 60)); //Today - $days $result = $wpdb->get_results("SELECT... [Read the full story]