WordPress plugins, themes, tips and hacks

Get to know every line of your comments.php WordPress theme file

Tuesday, June 3rd, 2008

There is one WordPress theme file that I almost never touch when working on a theme: comments.php. I usually style WordPress comments via the CSS sheet, and that’s that.

Well, there’s a lot you can do to customize and extend WordPress comments if you just know how. Nettuts has published a comprehensive tutorial on how the comments.php file works, and what every line of code does. The tutorial also explains how to add extra goodies to your comments, like Gravatars, comment numbers, comment links, alternating colors (which we’ve discussed here), displaying the HTML tags users can use in the comments text box, and displaying a link to the comments RSS feed. The tutorial did not discuss how to give each comment its own link, a tip that I find particularly handy for referring to specific comments.

Check out this tutorial if you want to strengthen your relationship with your WordPress comments.

Unraveling the Secrets of WordPress’ Comments.php File

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Using WordPress comments as a contact form

Monday, February 4th, 2008

Justin Tadlock has posted a way to use built-in WordPress comments in lieu of a contact form. Basically, you replace your theme’s current comments.php file with the one that Justin offers for downloading that checks if a page is called “Contact.” If it is, the comments stay hidden on that page. You can change the comments.php file so that other pages on your site will also hide comments.

Then you can create your contact page which will display the comment form, but any comment submissions will stay hidden.

The advantages:

  • Don’t need to use another plugin
  • Don’t need to tweak a plugin
  • Can theoretically manage all contact form submissions from your site rather than via email.

The disadvantages:

  • Submissions are actually comments, so they end up in your comment queue. If you have a lot of comments on your site, that can get hard to manage.
  • if you ever change themes or your “comments.php” file, then your comments on your “Contact” page will no longer be private. This can be solved by deleting all of these types of comments, which I personally don’t like because I like to save letters from readers; or using this solution forever, which is kind of a long-term commitment.

It’s an interesting idea, and worth considering.

Even Simpler WordPress Contact Form

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Allow users to use OpenID to interact with your blog with OpenID WordPress plugin

Monday, January 21st, 2008

The WordPress OpenID plugin lets visitors to a Wordpress blog quickly register, login, and leave comments using their OpenID Identity. Says it’s designed for WP 2.0.3 to 2.1, but may work with 2.3.

Wordpress OpenID Plugin

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Make your WordPress comments more user friendly with a mini TinyMCE editor

Sunday, December 30th, 2007

WordPress comment boxes tend to be dry, text editors. That’s kind of ok for people who know HTML, but even I get frustrated when I want to add a link in someone else’s comment box.

Here’s a really easy and pretty solution: Advanced TinyMCE Editor. This editor add a simple yet useful toolbar to the top of the comment box with the following buttons: bold, italic, underline, strikethrough, undo, redo, add link, remove link, and view HTML. To see it in action, go to the comments section at the end of this post - I’ve implemented it here on WordPressGarage.

TinyMCE Comments»

Update March 10, 2008: I have disabled this plugin because a user notified me that it was causing Safari to crash. Oh well.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Using PHP to alternate background colors for comments or posts in WordPress

Wednesday, December 26th, 2007

Some blogs have alternating background colors for their comments and posts, i.e. a green background for every even comment and post, and a grey background for every odd comment and post. How do they do that?

Alternating Comments Styles

To alternate comments, add the following code to your comments.php template file, under where it says <?php if ( $comments ) : ?>:

<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 {echo 'class="even"';} ?>>

Then, create a style called .even and a style called .odd in your style.css file. Give each style a different background color, like this (but change the colors to what you want):

.odd {
background-color: #fcf9fc; }

.even {
background-color: #616161; }

This information is from the following WordPress support topic:

How to alternate background colors of comments posted on blog?

Alternating Post Styles

Adam Brown has a tutorial on his site for creating alternating styles for posts. Basically, you do the following:

  1. Right before the loop begins, add the following code:
    <?php $odd_or_even = 'odd'; ?>
  2. Right after the loop, there will be a div. Let’s say it’s called class=”post”. Change it to
    <div class="post <?php echo $odd_or_even; ?>">, and then add the following piece of code on the next line: <?php $odd_or_even = ('odd'==$odd_or_even) ? 'even' : 'odd'; ?>
  3. Now, create .odd and .even styles in your style.css.

Adam’s site has another really useful PHP Tutorial for Wordpress Users, which is good for those of us who aren’t going to become PHP gurus, but would like to know enough PHP to extend our WordPress sites.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Giving each comment its own link in WordPress

Wednesday, November 28th, 2007

Being able to link to specific comments in your WordPress blog could be very handy. Good comments can really add a lot of value to a blog, and you or others may want to refer to specific comments in your posts by linking to them. In general, comments can be linked to, but to figure out what the URL is for every comment is virtually impossible, unless…you set up your comments section of your blog so that every comment gets a link.

Here’s how you would create a link around the date and time of your comment:

<p><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a></p>

This piece of code should appear in your comments.php theme file where your comment code appears.

If you want an “Edit Comment” link to appear next to the comment for those who are logged in and have permissions to edit, you would add the following code:

<p><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a><?php edit_comment_link('Edit comment',' ~ ',''); ?></p>

So there you have it boys and girls: now you can link to comments, and share the love with your commenters!

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Recent Comments code snippet

Friday, November 9th, 2007

This code is from the Blog Oh Blog theme, and displays recent comments in the sidebar without the need for a plugin:

<?php
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
$output .= "\n<ul>";
foreach ($comments as $comment) {
$output .= "\n<li>".strip_tags($comment->comment_author)
.":" . "<a href=\"" . get_permalink($comment->ID) .
"#comment-" . $comment->comment_ID . "\" title=\"on " .
$comment->post_title . "\">" . strip_tags($comment->com_excerpt)
."</a></li>";
}
$output .= "\n</ul>";
$output .= $post_HTML;
echo $output;?>

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Akisment Auntie Spam picks up where Akismet leaves off

Tuesday, September 18th, 2007

Akismet brilliantly catches most comment spam and saves it in the Akismet section of our WordPress blogs. But if we don’t check Akismet regularly, we can find ourselves hundreds, if not thousands, of comment spam waiting for review. Since Akismet sometimes mistakenly identifies legitimate comments as spam, we need to pick through the spam garbage to see if any poor sincere commenters have gotten lost in there.

This is a virtually impossible task, since the comments are listed over pages and pages. Often, I just delete all and hope for the best.

Well no more! When I realized that Akismet Auntie Spam is not a WordPress plugin but a Firefox Greasemonkey extension, I was ready to give it a try. (I don’t have anything against plugins - I love them - but I’m worried that too many will slow down my blog.)

Once installed in your Firefox browser, Akismet Auntie Spam detects when you are on the Akismet page in your blog, and organizes all your comments onto one page with only one line of the comment displayed. The comments are ordered according to the number of comments submitted by a computer. So, for example, all comments submitted only once by one computer appear at the top of the screen and are highlighted in yellow. Comments submitted three times and up are highlighted in red, and each comment only appears once.

By using Akismet Auntie Spam, I managed to review and delete almost 500 comments within minutes!

How to install Akisment Auntie Spam:

  1. Make sure you have Firefox.
  2. Install the Firefox Greasemonkey script: go to the Greasemonkey Firefox add-on page and click Install now. Once the script is installed, restart Firefox.
  3. Go to Akismet Auntie Spam, and download the script. Install, and restart Firefox.
  4. Login to your blog, and go to the Akismet page. Watch Auntie Spam get to work reorganizing your spam.
  5. Peruse and delete at will.
  6. More instructions can be found on the Akismet Auntie Spam page.

This extension makes comment spam manageable. Not enjoyable, but manageable.

Managing Spam Maintenance with Akismet Auntie Spam Version 2»

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Contactify - trying to prevent comment spam

Sunday, April 22nd, 2007

Contactify is a new service that is supposed to allow people to contact you while hiding your email address, and thus preventing comment spam.

I say supposed to, because I’m having trouble figuring out what the advantage of the service is. Here’s a play-by-play of my experience:

  • Went to website and signed up with their “Super Fast Sign-Up Box.” It really is super fast, only that once I entered my info, my link did not appear, “like magic,” as it was supposed to. Nothing actually happened on the site. I did soon receive a confirmation email telling me to click on a link to confirm my subscription, and also telling me what my link number was. I clicked on the link.
  • I got a notice on the Contactify site that my subscription has succeeded. But I still couldn’t find my contact form.
  • On the main page, there was a link to an example contact form, with the following format: http://www.contactify.com/1. I replaced the 1 with the link number I had received in the email, and found my contact form.
  • So it seems that the form is not something you can embed on your site. I guess you’re supposed to provide a link on your site that says something like “Contact Us” and links to your Contactify form. This is a drawback since it takes people who are trying to contact you and are interested in you and your site - to another site!
  • Now that I had found my form, I decided to send myself a test message with my form. Everything was fine until I got to the Captcha numbers. I couldn’t read them! I entered them once, and was told I was wrong. The numbers changed and I tried again. Wrong. I clicked on “can’t read code,” but the numbers would change no more. I was told I needed to activate cookies.
  • Finally I managed to send myself a comment. The results were very basic, i.e. Sender Name: John Doe; Sender Email Address: and then the message.

As far as I know, when you install one of the WordPress comment forms, your email address is hidden. These forms are easy to use, and the ones that use Captchas are humanly possible to read. Contactify is in beta, so maybe they will improve, but in the meantime it seems like it’s not worth using their service. If their service does have advantages that I’ve missed, they really should improve the copy on their site so that it comes across to visitors.

Contactify>> 

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Wordpress Plugin: Comment Email Responder

Sunday, April 22nd, 2007

The Comment Email Responder plugin is one of those plugins that make you wonder why no one else ever thought of it. This handy plugin makes it easy for a WordPress administrator to respond to a comment and simultaneously send an email to the commenter. If the commenter has subscribed to receive notification of any new comments, the email is not sent. Brilliant! I’ve often found myself responding to a commenter, and then searching through my comments in the admin for their email address so I can send them an email saying that I’ve responded. This plugin pares the process down to one simple step.

Wordpress Plugin: Comment Email Responder>>

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
Premium News Themes