Top

How To: Adding the Post Authors Gravatar To Their Individual Posts

June 7, 2008 by Tony · Leave a Comment 

One thing I am really excited about is that Gravatars are really starting to gain popularity now that Automattic has purchased and is supporting them.  And now that support is built right into WordPress, it opens up a lot of options for WordPress users.

The most common place you’ll find a Gravatar is usually with an individual comment to help comments stand out.  Another place you will sometimes see them is in the sidebar, like we have it setup here at Hack WordPress.   One thing, however, that people are slowly coming around to is using Gravatars with blog posts to identify the author of the post.    This is something that is a great idea for a multi-author blog and something I’ve considered doing on this website.

So, how would you go about setting up Gravatars to display with each individual post?   Over at ThemeShaper, Ian Stewart recently shared an easy way to do this.   You just need the following code:

<?php echo get_avatar( get_the_author_email(), '64' ); ?>

When used, WordPress will match up the e-mail address associated with the post author to determine what Gravatar to use.   The 64 is the size (pixels) of the Gravatar.

Great find Ian!

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

How To: Display The Most Recent Comment First

June 7, 2008 by Tony · Leave a Comment 

By default, a typical WordPress blog will display the very first comment at the top of the comments template. While I prefer this way, many others do not. If you are someone that would like your WordPress blog to display the most recent comment on top, Moses of WPThemesPlugin.com explains how to display recent comments on top.

Unlike most of the WordPress hacks we’ve covered here at Hack WordPress, this one is not something that can be controlled from within the WordPress theme. You’ll have to actually go into the comment-template.php file (in the wp-includes folder) in order to make this adjustment. The good news is that it is REALLY easy. Click over to get step-by-step instructions on how to complete this hack. Great work Moses!

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

How To: Separating Your Author Comments in WordPress

June 6, 2008 by Tony · Leave a Comment 

Have you noticed while visiting some of your favorite blogs that many author comments are styled differently to help the authors comments to stand out? This is something that isn’t overly difficult to implement on your WordPress blog, so I decided to write a quick how-to post explaining how you can easily adjust your WordPress theme to display different styles for each author.

First, you’ll need to make some adjustments to the comments.php code. Look for something similar to the following code:

<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">

Replace the above code with the following code:

<li class="<?php if ($comment->comment_author_email == "admin@yourdomain.com") echo 'author'; else echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>">

You’ll want to modify admin@yourdomain.com to reflect the primary blog author’s e-mail address. This will tell WordPress to check each comment to see if you are the author. Now go to your CSS Stylesheet (style.css) and add the commands you would like to use for your author comments. You’ll want to use .author to style your author comments. I recommend pulling your standard comment code, then adjusting the colors to look different on your comments. You can also add a logo through your stylesheet.

How do I do this if my blog uses multiple authors? If your blog features several different authors, you’ll want to make a slightly different adjustment to the above code so that it looks like this:

<li class="<?php if ($comment->comment_author_email == "author@yourdomain.com") echo 'author'; else if ($comment->comment_author_email == "author2@yourdomain.com") echo 'author2'; else if ($comment->comment_author_email == "author3@yourdomain.com") echo 'author3'; else echo $oddcomment; ?> item" id="comment-<?php comment_ID() ?>">

In the above example, we are assigning the primary author as .author and adding their e-mail address where it says author@yourdomain.com. When the comment includes that e-mail, it will use the .author style from the stylesheet. The second author will use .author2 for their stylesheet and replace author2@yourdomain.com with the 2nd author’s e-mail, etc. Any comments that don’t include one of the above e-mails will use the standard styles.

Once you’ve got your code adjusted and added the author(s) commands to your stylesheet you will be ready to start commenting!

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

How To: Separate WordPress Comments and Trackbacks

June 6, 2008 by Tony · 1 Comment 

With all the WordPress themes available to WordPress users, it always surprises me how these incredible theme authors don’t take a few extra seconds to separate their theme’s trackbacks from the comments. It doesn’t look very professional and it can make it extremely difficult to follow a conversation in the comments.

Separating your trackbacks and comments requires a minimal amount of coding work to set up. First, you’ll want to make a backup of your comments.php file just in case something goes wrong. Next, follow these three steps:

1 ) Access your comments.php file and locate the following code:

<?php foreach ($comments as $comment) : ?>

Immediately after the above code, you’ll want to place this code:

<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type == 'comment') { ?>

2 ) Next, you’ll want to scroll down a little bit and locate the following code:

<?php endforeach; /* end for each comment */ ?>

Immediately before the above code, you’ll want to place this code:

<?php } /* End of is_comment statement */ ?>

This will filter out all of the trackbacks and pingbacks from your main comments loop. Now we need to create a second comments loop to display the trackbacks and pingbacks.

3 ) Almost immediately below the code from step 2 you should find this code:

<?php else : // this is displayed if there are no comments so far ?>

Immediately before the above code, you’ll want to place this code:

<h3>Trackbacks</h3>
<ol>
<?php foreach ($comments as $comment) : ?>
<?php $comment_type = get_comment_type(); ?>
<?php if($comment_type != 'comment') { ?>
<li><?php comment_author_link() ?></li>
<?php } ?>
<?php endforeach; ?>
</ol>

You can adjust this code to display how you want to, including using a different header if you have a specific look for your header 3.

[del.icio.us] [Digg] [Facebook] [Google] [MySpace] [Newsvine] [Reddit] [Slashdot] [StumbleUpon] [Technorati] [Windows Live] [Yahoo!] [Email]

Bottom