Rae Hoffman

Thesis Tutorial – Creating Custom Categories

by Rae Hoffman on March 28, 2009 | Blogging It

Creating Custom CategoriesI get asked at least once per week how I got the custom content on my category pages (you can check out the affiliate marketing category here on Sugarrae or the SEO conference category on Outspoken Media to see examples). The answer are custom category hooks and the instructions for creating them are below.

Now first, I’d like to say that having custom categories is possible in any Wordpress theme. So, if you’re not using Thesis, all you need to do is duplicate the basic category.php template of your theme and and then customize it for each category, name it category-#.php (with # being the actual number of the category you have customized that template for) and upload it to your theme file. Wordpress by default will first check for a category-#.php file before it renders the plain category.php if a custom one does not exist.

That said, if you plan to customize every category on your blog, I’d highly suggest switching to the Thesis platform. Why? Well, if you go to change blog layouts or designs in the future, you will have to re-create every single custom category template in the new theme. With Thesis, if you change the design, the hooks still remain. You do it once and don’t have to worry about it again.

For those of us already on the Thesis theme, adding the hooks to do the custom categories is fairly easy. However, please note that you need to be on Thesis 1.4 or higher for the instructions below to work. If you’re still using an older version of the theme, you need to upgrade. I’d also recommend reading hooks for dummies before attempting the below so you get an idea of how hooks work so the code below makes more sense.

Creating Custom Categories

Let’s say you want to add some custom text to the top of your “apples” category page, above where the listing of your posts in that category appear and different custom text to the top of your “oranges” category page.

Step 1: Open your custom_functions.php file (thesis > custom > custom_functions.php) in your favorite editor

Step 2: Underneath the example code already in the file, place the following code (this code assumes your blog is in the root):

/* Custom Categories */
function custom_archive_info() {
if (is_category('apples')) {
?>
<div class="post_box top intro_block">
<div class="headline_area">
<h1><?php single_cat_title(); ?></h1>
</div>
<div class="format_text">
<p>YOUR CUSTOM APPLES TEXT HERE</p>
</div>
</div>
<?php
}
elseif (is_category('oranges')) {
?>
<div class="post_box top intro_block">
<div class="headline_area">
<h1><?php single_cat_title(); ?></h1>
</div>
<div class="format_text">
<p>YOUR CUSTOM ORANGES TEXT HERE</p>
</div>
</div>
<?php
}
else
thesis_default_archive_info();
}
remove_action('thesis_hook_archive_info', 'thesis_default_archive_info');
add_action('thesis_hook_archive_info', 'custom_archive_info');

The /* Custom Categories */ is a label for the code below so you know what it is at a single glance. This is not part of the actual “code”. The word “function” tells Thesis you want it to do something. The custom_archive_info is what I decided to name that function.

The if (is_category(’apples’)) tells Thesis the category archive page you are looking to alter is the apples category. It goes by post slug of the category. So if the url of your category page is www.yourblog.com/category/learning-seo/ then you would use if (is_category(’learning-seo’)) in place of if (is_category(’apples’)). This line says IF the category is “apples” then insert the custom text below.

Now, the next portion of the code is an “else if” statement. If the category is apples, then it will insert the specified text outlined in (is_category(’apples’)) OR if (elseif) the category is oranges, it will insert the specified text outlined in (is_category(’oranges’)). The last portion of the code (else) basically says if it is anything else aside from the categories specified above, then use this default code (which happens to be the regular Thesis category page).

So you start with the initial “if” statement (the first category that you specify – choose any one you want) and then all subsequent categories would be “elseif” statements followed by the “default” “else” statement of what to use if you haven’t specified anything specific.

You can add more categories by simply adding more “elseif” statements:

elseif (is_category('yet-another-category')) {
?>
<div class="post_box top intro_block">
<div class="headline_area">
<h1><?php single_cat_title(); ?></h1>
</div>
<div class="format_text">
<p>YOUR CUSTOM TEXT FOR THIS CATEGORY HERE</p>
</div>
</div>
<?php
}

Between the first “elseif” statement and the “else” statement in the example above:

elseif (is_category('oranges')) {
?>
<div class="post_box top intro_block">
<div class="headline_area">
<h1><?php single_cat_title(); ?></h1>
</div>
<div class="format_text">
<p>YOUR CUSTOM ORANGES TEXT HERE</p>
</div>
</div>
<?php
}
ADD MORE ELSEIF STATEMENTS (AKA CATEGORIES) HERE
else
thesis_default_archive_info();
}

The last two lines of the initial code example above:

remove_action('thesis_hook_archive_info', 'thesis_default_archive_info');
add_action('thesis_hook_archive_info', 'custom_archive_info');

Basically tell Thesis you want to remove the “thesis_default_archive_info” function (the default category instructions) from the “thesis_hook_archive_info” and replace it with the “custom_archive_info” function (which contains the new category instructions you just made).

Creating Custom Tag Pages

If you use tags instead of (or in addition to) categories and would like to create custom pages for those as well, just replace:

(is_category('yet-another-category'))

with:

(is_tag('tag-slug'))

If you’re using the Thesis theme already and have read my other Thesis tutorials you’ll probably find this process pretty easy. If you haven’t made the switch to using Thesis yet, I’d highly recommend you read my review of the Thesis theme, as well as the tutorials to get a sense of why I am such a loud-mouthed and enthusiastic evangelist for this theme.

Subscribe to the Sugarrae feed | Follow Sugarrae on Twitter

Related Posts

Sugarrae runs on the Thesis WordPress Theme

Thesis WordPress theme

If you’re a blogger looking for a professional presence but don’t understand a lot of PHP, Thesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel. With the incredible customization possibilities via Thesis hooks, you can easily make your blog stand out from the crowd.

Thesis allows bloggers to make more professional customizations than they may have ever deemed possible due to lack of coding knowledge. The theme allows me to run Sugarrae more professionally, with a focus on monetization that is more targeted than I’ve ever been able to achieve with a theme before. You can find out more about Thesis below:

{ 32 comments… read them below or add one }

1 The Mules March 28, 2009 at 8:16 pm

Very nice Rae… whispers behind the barn suggest this will be linked to frequently from the Thesis support forums.

2 Philip Barron March 28, 2009 at 11:48 pm

Now how did you know I was wondering about this very thing earlier today? Get out of my head!

(Just kidding. Please keep up the telepathy, and thanks!)

3 Gab Goldenberg March 29, 2009 at 3:13 am

Funny, I was just talking to someone about creating a plugin to do this on [non-Thesis] themes.

Anyways, is there a way to do this without repeating the else if statements for every category? Suppose you have 100 categories. On each of 10 blogs. Gets tedious… Thoughts?

4 Hendrik March 29, 2009 at 12:22 pm

Is it possible to merge the Thesis theme with my own blog’s design? I am no coder myself.

The category pages rock, a lot better than on my blog.

5 Todd Heim March 29, 2009 at 1:09 pm

You ROCK! Thanks a bunch!

6 steaprok March 29, 2009 at 4:19 pm

Once again, awesome thesis tutorial! informative, concise and to the point!

7 Rae Hoffman March 29, 2009 at 5:22 pm

Gab, either way, you’d have to write the unique content for each of those category pages, so curious as to what the difference of putting that unique content into the elseif statement each time?

8 Kaz Clark March 29, 2009 at 6:26 pm

Thank so much; need to fiddle with some titles and the fact my funny e’s (french) showing up as questions marks but will sort it.

If you wanted to bung an image in too would you just stick scr in? I am a but “sensitive” re image placement at moment as have spent week trying to get images in place I want and am failing to call it right as get bits of code showing too – - another subject for you ; ) … placing images in specific places on specific pages with hooks … full code version.

Your style is great; easy to follow and very instructive and easy to follow. Plus, huge benefit for newbie – it goes from beginning to end rather than launching in middle!

Only other issue I’be had is I did the ol’ get H1 and H2 on pages way out there which means my headers for this box screwy – hence the question re placing an image in this code.

Fab site, thanks!

9 Emilio March 30, 2009 at 7:26 am

good Post Rae , also I had started following your on twitter. I read your blog daily (whenever it updates) and just hoping that I also learn something from you.

10 wheel April 3, 2009 at 9:39 am

I have a feeling that what I should be seeing here is less a tutorial and more an affiliate marketing case study :).

11 Emplic April 10, 2009 at 3:29 pm

More and more I see why so many people are using the Thesis theme… and more and more people are getting involved as affiliates, contributors and developers. These is taking over the world!

Back to reality… thanks for the ‘creating custom categories’ tutorial. Hadn’t thought about category content in this sense before — the results are nice. May have to switch to Thesis down the road…

Hooks for dummies link also appreciated.

12 Pedro April 14, 2009 at 11:12 pm

Would this help me make my Home page act as a Category Page in the Nav bar? I have specific posts (in a single category) that i would like to constantly appear on the Home (front/main) Page. [hard part]

Then, I can create a Category Page in the Nav Bar and call it News. Next, I add all new posts to the “news” category. [easy part]

I basically want certain posts to always be on top/on the front page.

Any thoughts?

13 Kitty April 16, 2009 at 8:49 pm

Hi Rae,
First time visitor here and my mind is spinning! Soooo much great info and my journey started by looking into purchasing the Thesis theme.
I’m happy to have found you.
:)

14 DangerMouse April 18, 2009 at 4:52 am

For larger category lists you may consider using a PHP Switch statement rather than an if elseif elseif elseif approach. It’s slightly cleaner and more efficient.

I’m currently considering Thesis and deploying Wordpress as a CMS rather than a blogging platform – in your experience Rae, how easy is it to add custom fields to the Admin interface?

Cheers,

DM

15 Melody April 18, 2009 at 7:35 pm

Every day there seems to be bigger and more effective wordpress themes being created by awesome designers.. I just recently changed my wordpress theme, so I hope it’s effective for now at least..

This is a nice theme though lovely colors..

16 Bart Gragg | Blue Collar U April 28, 2009 at 8:51 am

Rae,

Now you’ve gone and done it.

I have three blogs, all on Thesis – which makes it a HUGE bonus as once I figure out how to get what I want on one I simply copy two files custom.css and custom_functions.php to the others, tweak the colors, and voila’!

I love the ability to work with Thesis sooo much that I am now in danger of scoliosis from being hunched over the keyboard, the Lasik surgery is wearing off from staring at the screen, carpal tunnel is imminent, and brain cells I didn’t know I had are aching.

But that’s me, always looking for another way to tweek things, and here you fed me yet another! Dangit!

Thanks!
Bart

17 JustinSail May 5, 2009 at 5:13 am

Thanks for the tip! This code: (is_category('yet-another-category')) was the key to my figuring this solution out! You were the final missing piece!

18 Anthony Hereld May 8, 2009 at 8:38 am

Another great tutorial, Rae!

Even for some of us who are more advanced Thesis users, it’s always great to see fresh ideas. Which reminds me…my Thesis site desperately needs an update. Maybe some custom categories are just what the doctor ordered!

Thanks!

19 Don Campbell May 25, 2009 at 6:00 pm

I just used this tutorial to set up custom category pages for my Thesis-based site and it worked perfectly. Thanks Rae!
-Don

20 leigh July 8, 2009 at 4:36 pm

Great post! Can you share how to do custom post templates in thesis?

21 One3rdNerd July 8, 2009 at 8:08 pm

Hey SugarRae, thanks for the breakdown. I used similar code to state different header images for each page, but wasnt sure of the differences with doing the same with catagories, also I didnt know you could use hooks to call up post content. Brilliant. Good Work :)

Thanks

22 Magnolia July 12, 2009 at 10:40 am

Hi Rae,

I found your site searching for tutorials on Thesis. I use it for two of my blogs.

Love what you’ve done with the theme and I plan to scour your site here for help with mine.

I’m not sure how old you are, but I was a single mom at one time too and determined as you seem to be to provide for and take care of my children. So, I have bonded with you in a “single mommy” kind of way. :)

No longer a single mommy and decidely middle-aged, I’m hoping you can help this fifty-something year old broad figure out this blogging for a living kind of thing. Age is irrelevant in the age of Internet and for that, I’m delighted.

I think I just need to hook my wagon to people like you and learn as much as I can. It may take me a while to figure out what kind of services you offer exactly. But, I’m inspired.

Great website, girl. :)

23 leigh July 16, 2009 at 12:06 pm

how would you do this in openhook?

24 shawn August 27, 2009 at 8:47 pm

I know this article is a bit dated, but it’s still relevant so I had a couple of quick questions.
1. Is it possible to have the template completely switch from the current layout to a completely custom layout with the system you are using? (I’m used to regular wp themes where I create a template file and then make a call to that for a page, thesis does not seem to be this way). Idea being that if someone clicks on a ‘video’ category, I could completely switch the layout to one more suited for video than blogging.
2. Echoing the question above about all the if/then statements. I was thinking the same thing. For my ‘model’ I will be using wp-mu so all my users get to use thesis. The problem is there is NO WAY I could ever allow them to insert php code for security reasons. It would be much easier using the traditional wp ‘custom pages’ way where they could assign a premade ‘template’ to their category.

I hope #2 makes sense.. kinda hard to describe.

well keep the lessons coming!
I only found this site a few days ago and have already read most of the articles. They are fantastic

25 Jenny August 29, 2009 at 6:37 pm

Hi Rae,
I am trying to figure this hook stuff out. I am having a devil of a time. I would like to display sidebars with different content on category pages, but can’t seem to figure it out! I have managed to duplicate sidebars ( I now have four), but what I can’t figure out is out to make (for example) sidebar 3 and 4 show up with category one, and sidebar 2 and 4 show up with category 2, etc. I have been copying/pasting different versions of your code above with now luck… any suggestions? I think the problem lies with not wanting the text, but different sidebars, and I don’t know how to call for them on category pages…. help!

26 Meethil September 3, 2009 at 12:18 pm

Hi Rae,

Your tutorial is really well written and crystal clear. Thanks.

Can you suggest how I can have the most recent post show up in full in place of (or below) the custom text on the category page.

Like – for example, when you go to the ‘apples’ category archive page, you will see the most recent post (in full, below the custom text if any) followed by excerpts of the older posts in the ‘apples’ category.

Can I add some sort of function in the custom text area to pull up the most recent post of that category?

Please advise.
thanks.

27 Farnoosh Brock September 26, 2009 at 10:22 pm

Excellent. I finally came back to original post here after reading the hook for dummies, and was able to successfully customize my categories. I was also wondering if there is a way to insert photos, and formatting in the text of each category page? I will experiment with things some more but would be nice to know your thoughts. Thank you!

28 Farnoosh Brock September 26, 2009 at 10:30 pm

Actually, I see that I can put any HTML code there, and it’s awesome. Thanks *so much*!! All set!!

29 Phil Barnhart October 5, 2009 at 2:25 pm

To avoid having to create a block for each category, I simply use the built-in WordPress category definition field:

function custom_archive_info() {
echo category_description();
}
then the thesis hook settings as in the original example. I then add HTML and text directly to the category description in WordPress. Add a little new CSS and done! No blocks of loops.

30 Jenny November 4, 2009 at 1:17 pm

Just a note – I followed these directions with the updated Wordpress and was having a hard time getting it to work – make sure that you are using the category SLUG – which can be found if you go to
DASHBOARD >UNDER POSTS, CLICK CATEGORIES – and the slugs are displayed in your category list –
in the above code I at first had replaced Rae’s “apples” and “oranges” category with my category id that shows up in my browser bar, but it was not working, until I switched it to the cateogory slug. Hope this helps someone save some time and headache!

31 rinus November 20, 2009 at 8:33 am

Hi, thanks for this tutorial. I also want to have more posts visible on the archives page than on the homepage. Is this possible?

32 Nicklas Larenholtz December 6, 2009 at 7:18 am

I´m trying to figure out how I ad a “archive_info” for a certain Category. In this hook I want some amount of text that tells a bit more about the category.

I be so happy if someone has the answer.

Leave a Comment

Want to add a picture to your comments here on Sugarrae? Upload a picture at Gravatar to make it happen.

Please note that by clicking submit, you agree to abide by the comment policy.