Designing with WordPress, Part 2: 3 simple tricks
Do you ever get sick of seeing the same thing over and over on WordPress blogs? They all seem to display 10 posts with a date, a few tags, and a comment count. There is a sidebar on the side with category lists and an archives list. It gets old fast, especially if you’ve designed more than a few templates. It’s fun to find ways to spice things up a bit, and here is a list of three things I’ve done lately.
1. Color Coded Categories
I recently finished this latest redesign of Bleikamp.com and one of the things I had been planning on doing was color coding my categories. Chris Pearson did a similar trick at 901am.com and David let me take a peek at the code. It’s a very simple piece of code that can add a bit of life to your theme. Note that this won’t work well if you are constantly adding new categories to your theme and treating them like tags.
The first piece of code looks something like this:
<?php $category = get_the_category(); $category = $category[0]; ?>
Go ahead and paste that into your WordPress loop.
Now you’re set up to experiment with color coding categories. It’s actually very simple using CSS. What I’ve done on Bleikamp.com is setup categories to display within their own <span>, it allows me to customize the colors for each category by assigning the class as the category name.
<span class="<?php echo($category->category_nicename); ?>“></span>
Tah-dah! The bold part is all you need to printthe category name anywhere in the loop (i.e. just recopy it to the space between the span tags to display the category name). So now, when you go to your CSS file, you simply setup a <span> with the class of the category name you want to style differently. For example:
span.blogging { background: #1268b1; }
span.politics { background: #2daf00 ; }
span.technology { background: #5600af; }
span.life { background: #bb0065; }
span.business { background: #c13200; }
span.design { background: #ffba00; }
span.quick { background: #333; }
You could make some categories bold, other italic, give them any background color you want, and so on and so forth. Be creative.
2. Show users where they are on your site by highlighting the current page in the navigation.
WordPress also makes this very easy. It just takes a few WordPress conditionals and everything is done. My code looks like this:
<li><a href="<?php bloginfo('siteurl'); ?>" <?php if (is_home()) echo(’class=”here” ‘); ?>>Home</a></li>
For a full list of the conditional tags check out the WordPress documentation. There is no excuse not to do this when WordPress makes it so easy.
3. You tell me what you want to know about designing with WordPress and I’ll write about it.
13 responses so far ↓
4 Mar 2007 at 1:13 am
Niice Post. I’ve always wondered how they make the nav links styled a certain way when your on a certain page. Once again, great post.
4 Mar 2007 at 9:11 pm
Why not just be simple and do:
<php if(in_category(1)) { $class=”category1″; }
else if(in_category(2)) {
$class = “category2″;
}
else {
if(in_category(3)) {
$class=”category3″;
}
echo ‘<div class=”post ‘.$class.’”>
?>
5 Mar 2007 at 11:18 pm
Aaron: Because.
21 Mar 2007 at 4:41 pm
You could also do something like:
cat_ID) {
case 1:
$catClass = 'class1';
break;
case 2:
$catClass = 'class2';
break;
default:
$catClass = 'genericCat';
break;
}
16 May 2007 at 1:37 pm
I am going to take you up on item 3.
You mentioned Chris Pearson. No doubt you read The Definitive Guide to Semantic Web Markup for Blogs. Write an article explaining how best to hack a theme to fit his post and/or publish a theme that fits his design concept. The problem is in the CSS, is it easier to create new div’s or tweak the old ones?
I caddied for the Golden Bear at Muirfield. Go Bucks!
10 Aug 2007 at 5:48 pm
I’d like to know how you got the comment section so organized in a table format.
Great site!!!
7 Sep 2007 at 7:59 pm
Hi all!
I see first time your site guys. I like you
Bye
21 Sep 2007 at 1:17 pm
Hi
I found lots of intresting things here. It very impressive. I will bookmark!
1 Dec 2007 at 10:56 am
Thankiossi
It’s great
2 Dec 2007 at 3:41 pm
Thankiossk
Cool!
5 Dec 2007 at 9:23 pm
lol
thankiossp!
15 Dec 2007 at 1:32 pm
greiitsite!
Thanks!
18 Dec 2007 at 4:38 pm
I haven’t gotten much done lately. So it goes. I feel like a complete blank. I’ve basically been doing nothing to speak of.
Leave a Comment