WordPress.org

Codex

Separating Categories

Contents

Your posts are filed in different categories. Category information is freqently displayed in the post meta data section near your post or under the heading title. Different WordPress Themes highlight the post meta data section in different areas.

The display of the post categories is generated through the use of the the_category() template tag. And you have the ability to style how these categories are displayed.

Finding Your Categories Tag

The placement of your categories tag may be in one place on the front page and in one or more different places in your single post page, so you may have to do some hunting to find your various categories tags. You might also want to style one differently from the others, but you still have to find them.

The post meta data featuring your categories tag in your Theme is usually found on the index.php, single.php, or sometimes in the sidebar.php template files. Open one or more of these template files and search for:

<?php the_category() ?>

Once you have found it, take another look at a generated web page of your site and determine how exactly you might want to change this information.

The the_category() template tag instructs the database to get the information regarding the post categories and display it at that point in your template file. By default, it displays the list of categories with a space between each one. You can change this by adding the parameter inside of the tag. Let's begin with simple separators by playing with the category names: WordPress, Computers, and Internet News.

Simple Separators

If you would like to have commas between the categories, the tag should read:

<?php the_category(',') ?>

And it would look like this:

WordPress, Computers, Internet News

If you would like to have an arrow, the tag would look like this:

<?php the_category(' > ') ?>
WordPress > Computers > Internet News

If you would like to have a bullet, the tag would look like this:

<?php the_category(' &bull; ') ?>
WordPress • Computers • Internet News

If you would like the "pipe" ( | ) between the categories, the tag would look like this:

<?php the_category(' | ') ?>
WordPress | Computers | Internet News


Adding Text to Your Categories

Would you like to make your post meta data look a little more textual, informal and part of a paragraph rather than a list. You can add an "and" to go between the categories like this:

<p>You can read related subjects in 
the <?php the_category(' and ') ?> categories.</p>
You can read related subjects in the WordPress and Computers and Internet News categories.

Or you can give them more of a choice and change the "and" to an "or":

You can read related subjects in the WordPress or Computers or Internet News categories.

The possibilities are endless. Have fun and use your imagination!