Last updated on November 28, 2011. Tags: category description, category page
WordPress category description is possibly one of the most underused and under appreciated feature of WordPress. You can type the category descriptions for each category in your WordPress administration panel.
However, unlike post excerpt, there is no obvious use of category description. You can use it in several different ways, but most bloggers opted to not use it at all ("most" might be an understatement, since I never encountered any blog that utilizes category description). One possible use of category description is to provide introductory text for the category pages.
To display the post description as an introductory text in your WordPress-powered blog or website, open the index.php file of your WordPress theme and insert the following codes immediately under the code <h1><?php single_cat_title(); ?></h1>.
<?php if ( is_category() ) { echo category_description(); } ?>
The if argument is_category() ensures that the category description will be called only if the page is indeed a category page. Note that WordPress also uses index.php to generate archive pages, tag pages and search results. We need to ensure that the category description will appear only in the category page.
It should look like more or less something like this:
<?php get_header(); ?>
<h1><?php single_cat_title(); ?></h1>
<?php if ( is_category() ) { echo category_description(); } ?>
<?php if (have_posts()) : ?>
.
.
.
In case you cannot find <h1><?php single_cat_title(); ?></h1>. you can check index.php to determine which line of code calls the header of the category page and place the code (that calls for category description) immediately under it.
You can insert HTML elements such as <br/> tags before and/or after the code to control the spacing between the header of the category page, the introductory text and the list of posts under that category. You can also insert advertisement codes such as Google Adsense in this areas.
Calling the category description (using echo category_description()) automatically inserts paragraph tags <p> and </p> before and after category description. If for some reasons you disabled the automatic insertion of paragraph tags, you can maintain it within paragraph block element by manually inserting the paragraph tag before and after the code as shown below.
<p><?php if ( is_category() ) { echo category_description(); } ?></p>
NOTE: If there are so many post under one category such that WordPress splits the category page into several separate pages, the category description / introductory text will appear on each of those separate pages. I am still looking for a way to implement it in the first page only. That's the reason why I'm not using this trick.
Shown below is a screenshot of one of my blogs using this technique. The introductory text, which was called from the category description, read as "Here are the list of topics about Physics, raging from mechanics, to ..." I was using a screenshot and not an actual website because I opted not to save this configuration in that blog. I only used that blog to test this code.
Posted by Greten on March 21, 2009 under WordPress
Comment Rules and Reminders
Posted by JessicaMem on 05.10.09 5:14 pm
Your site displays incorrectly in Firefox, but content excellent! Thank you for your wise words:)
Posted by Greten on 05.11.09 2:40 pm
Thanks Jessica
I was using Firefox ver. 3.0.7 and it looks perfectly in my browser. What version of Firefox do you use?
Posted by Andreas on 10.25.09 12:44 pm
Finally I found a website that shows me how to do this! Thanks for the excellent description and code that works every time. I personally had to implement this in the archive.php page as it was not showing in index.php or single.php I guess it depends on the wordpress theme you are using.