Thesis Tutorial – Creating Custom Categories

I 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). The answer are custom category hooks and the instructions for creating them are below.

PLEASE NOTE:

The below Tutorial is deprecated as you now have the ability to create custom headings and custom intro content via the WordPress admin without using any code. Go to your WordPress Dashboard > Posts > Categories > and click edit on the category you want to create custom intro content for. By adding custom text to the “Introductory Headline” box and the “Introductory Content” box, you can create custom intro content for your categories without touching custom functions. The same goes for tags.

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.

About Rae Hoffman

Rae Hoffman aka "Sugarrae" is an affiliate marketing veteran and the CEO of PushFire, a search marketing agency specializing in SEO audits and link building strategies. She is also the author of the often controversial Sugarrae blog. You can connect with Rae via Twitter, Google+ and Facebook.

Sugarrae runs on the Genesis Framework

Genesis Framework

If you’re someone who doesn’t understand a lot of PHP, Genesis will give a ton of functionality that you wouldn’t be able to obtain otherwise with a simple control panel instead of having to alter code. For the advanced, Genesis has incredible customization possibilities via Genesis hooks.

The theme is not only highly customizable, but it has allowed me to run Sugarrae more professionally, with a much more targeted focus on monetization than it ever has been able to achieve before.

You can find out more about Genesis below:

Speak Your Mind

*