PMG Digital Made for Humans

Three Ways to Make Your WordPress Category Pages Better

2 MINUTE READ | July 22, 2011

Three Ways to Make Your WordPress Category Pages Better

Author's headshot

Christopher Davis

Christopher Davis has written this article. More details coming soon.

Let me be honest with you: your WordPress category pages suck. It’s okay, it’s not your fault. Most theme designers don’t realize the value of a good category pages. Here are three ways to make yours better.

WordPress comes with a feature few theme developers make use of: the taxonomy description. It’s a short bit of text that describes your taxonomy (category, tag or custom taxonomy), and you can see the input for this thing on the “edit category” or “edit tag” page.

Call this into your category.php file with category_description. I like to stick this in right below the first heading tag.

<?php echo category_description(); ?>
<?phpif(have_posts()):?>
<div class=“post clear”>
    <h1><?phpsingle_cat_title();?></h1>
        
    <?phpechocategory_description();?>

If you run a larger site with many subcategories, you should provide a way for your visitors to find their way around. Listing subcategories is one way to that.

So right below your category desciption, add some more code. First, we need to get a list of categories that are children of the current category. For this, we’ll use wp_list_categories.

<h2>Subcategoriesof<?phpsingle_cat_title();?></h2>
<?php
wp_list_categories(
    array(
        ‘child_of’=>get_queried_object_id()
    )
);
?>

This would work, except “Subcategories of [Some Category]” will always be on every category page regardless of whether it had subcategories or not. Instead, let’s change our code a bit to use get_categories, which will return an array. Once we have that, we can check to make sure we actually have categories before printing anything to the page. Then we loop through each category, getting the link with get_category_link. Note that get_categories returns an array of objects, so we already have the category name ($cat->name) and ID ($cat->term_id) for each category.

<?php endif; ?>
<?php
$cats=get_categories(array(‘child_of’=>get_queried_object_id()));
if(!empty($cats)):
?>
<h2>Subcategoriesof<?phpsingle_cat_title();?></h2>
<ul>
    <?php
    foreach($catsas$cat)
    {
        echo‘<li><a href=”‘.get_category_link($cat->term_id).‘”>’.esc_attr($cat->name).‘</a></li>’;
    }
    ?>
</ul>
<?phpendif;?>

If you’re not using WordPress’ built in post thumbnails, you should be. From an SEO perspective, images add a valuable aspect to the page. So why not use them?

Enable post thumbnails in your theme by adding the following your your functions.php file

add_action(‘after_setup_theme’,‘pmg_add_thumbs’);
functionpmg_add_thumbs()
{
    add_theme_support(‘post-thumbnails’);
}

Stay in touch

Bringing news to you

Subscribe to our newsletter

By clicking and subscribing, you agree to our Terms of Service and Privacy Policy

Then, somewhere in the loop, you can call the_post_thumbnail to display the image.


Related Content

thumbnail image

AlliPMG CultureCampaigns & Client WorkCompany NewsDigital MarketingData & Technology

PMG Innovation Challenge Inspires New Alli Technology Solutions

4 MINUTES READ | November 2, 2021

thumbnail image

Applying Function Options to Domain Entities in Go

11 MINUTES READ | October 21, 2019

thumbnail image

My Experience Teaching Through Jupyter Notebooks

4 MINUTES READ | September 21, 2019

thumbnail image

Working with an Automation Mindset

5 MINUTES READ | August 22, 2019

thumbnail image

3 Tips for Showing Value in the Tech You Build

5 MINUTES READ | April 24, 2019

thumbnail image

Testing React

13 MINUTES READ | March 12, 2019

thumbnail image

A Beginner’s Experience with Terraform

4 MINUTES READ | December 20, 2018

ALL POSTS