Tutorial: Adding Gravatars to Cutline Themes

April 13th, 2009 · Tutorial, Wordpress Themes

Despite the growing internet presence of Chris Pearson’s Thesis, his older themes still remain popular, including the Cutline theme which I’ve modified for this blog.

I recently decided to add gravatars to my theme, so I launched a search for anyone’s tips on best positioning of the gravatar code within Cutline. Since I didn’t find anything, I did it on my own–but I thought I’d share with you exactly which code to put where to get gravatars on Cutline positioned like mine. As a bonus, a small section at the bottom shows you how to create a add a custom default gravatar for your site. You’ll see that commenters without gravatars get a ghosted black-and-white BC avatar.

Inserting Gravatar Code into Cutline Comments

1. Inserting the code into comments.php.

a) Navigate to Theme Editor and open comments.php.

b) Scroll down to <p class=”comment_meta”>

c) Insert

<?php if(function_exists('get_avatar')) { echo get_avatar($comment, '50'); } ?>

directly before <p class=”comment_meta”>

d) The result should look like: &amp;amp;amp;lt;?php if(function_exists(’get_avatar’)) { echo get_avatar($comment, ‘50′); } ?&amp;amp;amp;gt;<p class=”comment_meta”>

e) Save.

(Note, if you want your gravatars to be bigger or smaller, change the ‘50′ to ‘40′ or ‘60′ or whatever size you want.)

2. Styling the avatars in style.css or custom.css.

a) If you’re playing by the Cutline rules and have made all your changes in the custom.css stylesheet (or haven’t yet made any changes), open custom.css. If you’ve already hacked style.css to shreds anyway, open style.css.

b) If you’re in custom.css, insert the following line:

.custom #comments .avatar { float: left; margin: 0 4px 0 4px; padding: 4px; border: 1px #ccc solid; }

If you’re in style.css, insert the following line:

#comments .avatar { float: left; margin: 0 4px 0 4px; padding: 4px; border: 1px #ccc solid; }

c) Save.

This will style your gravatars with 4 pixels of padding on either side, then a 1px light-gray border, then a left/right margin to set them off. They’ll sit on the top left of your comments and the comment will wrap around them.

3. Turning on Gravatars.

Now your theme is set up for gravatars, but they may not be turned on. Navigate to Settings -> Discussion and enable gravatars, select the highest rating you’ll display, and choose a backup. Save those settings and watch the gravatars show up in your comments section.

Adding a Unique Default Gravatar

Now that your site has gravatars, you’ll find out just how many of your commenters don’t have them. You can select a mystery man, the gravatar logo, a blank space, or some randomly-generated icons to fill the space. Or you can create a special gravatar for your site. For example, I took the BlogCrafted gravatar, turned it black-and-white, and ghosted it. It shows up when people leave comments and aren’t signed up with gravatars, that’s what shows up for them.

Turns out that adding a gravatar that’s unique to your site isn’t hard at all. First you have to come up with a default avatar. In my example, it’s saved as defaultgravatar.jpg. If you use a different filename, be sure to change that in the code.

Upload the gravatar to the images folder of your theme directory (in Cutline, it’s called “images,” if your theme is different, please modify the code below to reflect its image folder name).

Then back in the Theme Editor area, navigate to functions.php (called Theme Functions). Directly under the:

if ( function_exists('register_sidebars') )
    register_sidebars(2);

paste:

add_filter( 'avatar_defaults', 'newgravatar' );  

function newgravatar ($avatar_defaults) {
$myavatar = get_bloginfo('template_directory') . '/images/defaultgravatar.jpg';
$avatar_defaults[$myavatar] = &amp;amp;amp;amp;quot;Unique Default Gravatar&amp;amp;amp;amp;quot;;
return $avatar_defaults;
}

The only things you might want to change in this code are:

1) make sure the image location /images/defaultgravatar.jpg is the same as your image’s location. In this case, it’s in the images folder of your theme and called defaultgravatar.jpg. Make changes as appropriate.

2) “Unique Default Gravatar” can be changed to whatever you want to call it.Don’t delete the quotation marks or the semi-colon that comes after.

Otherwise, unless you know PHP, you don’t want to mess with this.

Turn it on. Now go to Settings -> Discussion. The new gravatar should appear in the list of default options. Select it, save, and voila! (if you’re using a caching plugin, you may have to clear it for this to take effect.)

Now there’s only one thing left to do–enjoy your blog’s new gravatars.

A special thanks to the helpful Build Internet article I found on changing default gravatars. Check it if you’d like to know how the code works and see images of what it’ll look like once you’ve done it.

Related posts:

→ No CommentsTags: ··

| Print This Post Print This Post

Registering Domains Away from Your Host

April 10th, 2009 · Website Hosting & Management

One of the most convenient ways to register domains is through your host. That way, you have everything in one place. They may even give you a free domain for signing up.

But there are some definite advantages to keeping your domain registration separate from your host–somewhere like GoDaddy. If you end up having irreconcilable differences with your webhost, you may end up temporarily locked out of your account, as Cath Lawson did.

That’s unconscionable behavior on Bluehost’s part, but it does happen. In the event that you need to make a speedy exit and and a clean break from your host, it’s much easier if you don’t have to worry about your domains being registered there.

For example, Cath Lawson was locked out of her account for several days due to high traffic and poor service. If her domain had been registered through GoDaddy and she had backup files, she might have been able to restore her site within a matter of hours.

How?

First, she would have to buy hosting elsewhere–either at another shared host like LunarPages or at somewhere more expensive (and hopefully more stable) like Media Temple, or even through the Lunar Pages virtual server plan (ok, maybe not).

Once she was able to login to her new hosting site (it can take a little while to hear back), she could upload her Wordpress files, create a database and import her old one, edit wp-config.php to reflect the new database information, and then switch the domain nameservers (DNS) at GoDaddy. As soon as the DNS propogated across the internet, her site would once again be available.

Of course, most of us don’t deal with quite that level of drama from our webhosts. Nevertheless, when the time comes to make a change from one host to another, it’s simply more convenient not to have to move the domain’s registration.

If you left because of poor customer service (even if it wasn’t as bad as what Cath went through) then it’s one less thing you have to take care of before you make a clean break. It’s one less stressor. If you chose to move because your site’s needs are expanding or you found a better deal, it makes the move easier and cleaner. There are no complicated codes to enter and no complicated processes. You simply change the DNS settings where your domain is registered and voila.

How do you handle your domain’s registration? I started out registering through my host, but now I register elsewhere.

→ No CommentsTags: ···

| Print This Post Print This Post

When Your Wordpress Blog Goes Blank - Possible Fix

April 6th, 2009 · Blogging with Wordpress

One of the many services I offer is migrating Wordpress blogs from one host to another. If you’re attempting to migrate your own blog, here’s one important tip: deactivate your caching plugin before you migrate (usually wp-cache or wp-super-cache).

You don’t have to deactivate any other plugins, if you’re migrating your entire database then it’ll automatically reactivate what you were using before. But caching plugins do not play well with blog moves.

If, once you’ve moved the site, all you see is a blank page—not an error page, your site is just a blank page with nothing on it—then check your wp-config file for the following line or something like it:

define('WP_CACHE', true); //Added by WP-Cache Manager

You can either disable the line by putting a “#” in front of it like so:

#define('WP_CACHE', true); //Added by WP-Cache Manager

or you can delete the entire line and trust the caching program to add it back in once you reactivate.

I encountered this issue on Media Temple. I don’t know if that’s because MT is a bit different or if I’ve always turned off the caching plugin before. It was quite easy to fix, but a real pain to catch.

So if your Wordpress blog is showing nothing but blank pages check your wp-config file–it may be an easier fix than you expected. (Also, check to make sure your new host doesn’t have an index.html file in your blog’s main directory. All you want is index.php and index.php.wpau.bak, index.html will keep the front page of your blog from showing up).

Related posts:

→ 5 CommentsTags: ···

| Print This Post Print This Post