One category page, multiple headings

Conditional PHP statements can be your best friend when developing for WordPress. They allow you to display information based on certain conditions. We can use WordPress’ internal meta data, such as tags and categories, to determine what to display in certain cases. In this case, we want to simply display a unique heading for various categories.

In your category.php page you’ll want to paste this code snippet:

Here’s a quick snippet of code that allows you to include any number of different headings using one category page. Of course, adjust the category id to your own.

<h1>Classifieds</h1>
<?php } elseif is_category('4')) { ?>
<h1>Environment & Real Estate</h1>
<?php } elseif is_category('18')) { ?>
<h1>Hot Buzz</h1>
<?php } elseif is_category('16')) { ?>
<h1>Product Plaza</h1>
<?php } elseif is_category('7')) { ?>
<h1>Menu Development</h1>
<?php } else { ?>

This is a basic, but powerful idea. You can use “elseif has_tag(‘tagname here’))” to do the same thing with tags instead of categories for instance.

Leave a Reply