This guest post was written by John of The WordPress Expert, where he writes about WordPress tips, services, themes, plugins, and more.  If you have WordPress knowledge and are interested in writing a post for Hack WordPress, please contact us.

Say you have an author page on your WordPress blog; but what happens when you find that your author archive URL looks like this?

http://example.com/author/Joe%20Smith/

Of course, you’d probably want to change your name to a more “URL-friendly” format like this:

http://example.com/author/joe-smith/

How do you do it?

Well, WordPress itself doesn’t let you (probably because the URL is intended to be a permalink), but it can still be accomplished through a simple database modification.

Here’s how. This is assuming your hosting account is setup with phpMyAdmin. (If you don’t have database editing experience, you might want to make a database backup just in case.)

  1. Go to your hosting account’s cPanel and click on the “phpMyAdmin” icon. If you don’t see it, look for a “MySQL Databases” icon, click it, scroll down to the bottom of the page, and then click the phpMyAdmin link.
  2. Select your WordPress database from the menu on the left.
  3. Select the wp_users table, and then click the “Browse” tab.
  4. Locate the row that has your username in the user_login column. Click the Edit button (the pencil icon) on that row.
  5. Enter the desired URL version of your name into the user_nicename field.
  6. Click “Go” to save your changes.

And that’s it! Your author archive will now show up at your new URL.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

One thing I’ve always loved to do is set up my blogs comments to display alternating background colors (although ironically I have not done so for this site yet). I’ve always felt that this helps give the comments a little more separation from each other and improve the overall look of the blog.

Because WordPress is full of loops (homepage, category, tag, etc.), this same theory can truly be applied all over your blog. David of CyberCoder posted yesterday a great hack to alternate the background of your blog posts. Here are the steps you need to take:

Create a loop counter. Right before the Loop begins set a variable to zero.

<?php
$x=0;
if (have_posts()) : ?>

At this point I would want the Background Color to change, insert code to test for an even number post, and if this is true, add an inline CSS style for the background that would override the stylesheet.

<?php if ($odd = $x%2){?>
<div style=”background-color:#404040;padding:10px 0px 10px 10px;”>
<?php }?>

Then, where the background color should return to the original state, run the same test for the even numbered post and close the div tag set by the Inline Style.

<?php if( $odd = $x%2 ){?>
</div>
<?php }?>

The final step is to add 1 to the counter for each post, which is done at the end of the loop.

<?php
$x++;
endwhile; ?>

Thanks for sharing this trick David!

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

For those of you unfamiliar with Robots.txt, it is a file that webmasters use to help control what aspects of their websites are indexed by search engines and what parts are not to be indexed. This is a great way to give you full control of how they view your website and help avoid duplicate content penalities, but using a Robots.txt has to be done properly and responsibly in order to avoid making matters worse or accidentally preventing your website from being indexed all together!

There are a lot of posts out there that talk about a Robots.txt file, how to set one up, etc. Unfortunately, many of these posts don’t apply specifically to WordPress and can often get confusing when you are trying to implement one for your website. Others tend to leave out a lot of important information that most people should have prior to attempting to add a Robots.txt file to their blog’s root directory.

Ask Apache is offering a Robots.txt file and updated Robots.txt file that you can download and use for your blog. You’ll of course want to customize it to meet your needs, including adding any directories that you have created since installing the base WordPress install that you don’t want them to be indexed.

I recommend you bookmark these posts if you plan to tackle adding a Robots.txt to your blog at some point in the future. Both posts provide a lot of valuable information and, as mentioned above, includes actual templates you can use for your website.

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

I recently got an e-mail from a reader wanting to know how to hide their sub-categories in WordPress. If you use WordPress 2.1 or newer, this is actually really easy to do.

All you need to do is open your stylesheet and add the following anywhere:

.children {
display:none;
}

You can also style the children accordingly this way if you’d like!

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

As blogging continues to evolve and WordPress themes continue to become more functional, it is my belief that we will start to see more themes using tabs to help manage sidebar content. The problem with sidebar tabs is that they require Javascript to use, so very few themes seem to be using them.

I won’t claim to be a whiz with javascript, but I found that creating tabs was not overly difficult. I’ve recently switched a section of my sidebar over to tabs on my other primary blog, Slick Affiliate, to help manage my sidebar content. So far I am very happy with the results. It allows me to provide readers with a bunch of different site navigation options while not really taking up any extra room, so people that want it can use and it isn’t in the way for people that don’t want to browse archives or see my top commentators.

If you are interested in doing something similar for your weblog, Headset Options wrote a series of posts studying the anatomy of a Magazine WordPress theme. The second post is actually dedicated to covering some types of javascript and focuses on Domtab and Tabber. You’ll find a nice examination and then a tutorial of how to add this to your WordPress blog. If you aren’t familiar with either type of javascript, I recommend you start with Tabber, as it is quite a bit easier to work with in my opinion.

What is your opinion of sidebar tabs? Do you find it more convenient or does it make the content harder to find?

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |

Have you ever noticed how some pages on blogs behave different than on other pages? One of the most under-utilised features of WordPress is the wide variety of conditional tags available in WordPress. Through the use of conditional tags, you can instruct certain plugins, pictures, or code to only appear on designated pages.

Recently I ran across a post by the Undersigned explaining Conditional Tags in WordPress, which appears was written in 2006 but is still valid with current versions of WordPress.

Here is a list of the conditional tags available:

  • is_home()
  • is_single()
  • is_page()
  • is_category()
  • is_author()
  • is_date()
  • is_year()
  • is_month()
  • is_day()
  • is_time()
  • is_archive()
  • is_search()
  • is_paged()
  • is_404()

One of my favorite places to use conditional tags is in the post meta area. For example, on most pages I want the comments button to display, but I don’t need it to appear on the single page because the comments are displayed on that page. At the same time, I like having an edit button on the single page, but I don’t need it on any other pages.

Here is the code I use for the above example on one of my sites:

<?php if (is_single()){ ?> <?php edit_post_link(__(”*Edit*”), ”); ?> <?php } else { ?> | <?php comments_popup_link(’0 comments’, ‘1 comment’, ‘% comments’); ?> <?php } ?>

The bold code is the conditional tags I’ve set up.  You can see from the above code that I am telling WordPress to only display an Edit button on single pages, and on all other pages display the comments link.

What other good uses have you found for conditional tags?

Digg This! | Stumble it! | Add to Del.icio.us | | Print This! |