How To Display Category Name And Description on Category Page in WordPress

Out of the box, many (perhaps most?) WordPress themes do not display the category name and description on the category page. I find that to be a bit lacking, especially since the category administration page allows you to enter both a name and description for each category.

Some themes, such as Atahualpa 3.4.1, display the category description in a tool tip (a.k.a. bubble help) when you hover your mouse over the category name in a category list widget. That’s nice but I wanted more than that.

Specifically, I wanted to display both the category name and description on the first page of each category but only the category name on subsequent pages.

The closest solution I could find for this was one put forth by juggledad, which I modified for my needs.

My solution was to add the following snippet of PHP code to the setting “Atahualpa Theme Options – Style and edit Center Column – Content Above the Loop”:

<?php /* JK: Display category title and description. */
if ( is_category() ) { ?>
<div>
  <h2>Category: <?php single_cat_title(); ?></h2>
  <?php
  if ( get_query_var('paged') < 2 ) {
    echo category_description();
  }
  ?>
  <br />
</div>
<?php
} ?>

The above code was tested on WordPress 2.8.4 with the theme Atahualpa 3.4.1. I was also using the plugin WP-PageNavi 2.50 but as far as I know, this plugin (probably) has no effect on this solution.

If you are using a different theme, you could put the above code in your index.php template or in your category.php or category-xx.php templates. I haven’t tested that however. I’ll leave that as an exercise to the reader. If you do try it, please post your comments back here.

Be Sociable, Share!

    9 comments to How To Display Category Name And Description on Category Page in WordPress

    • Joe

      Thanks! perfect works great. How would i style the wordage?

    • By “wordage”, I assume you mean the category description text? You can style that text by first making a CSS class. If you are using the Atahualpa theme, simply add your CSS class to the “CSS inserts” setting in the Atahualpa theme options. If you are using a different theme, you’ll have to add the class to your theme’s main stylesheet (probably called something like style.css). After making the CSS class, you’ll need to modify my PHP code snippet shown in the above post. Specifically, you’ll need to wrap the category text with a “div” or “p” element and assign your new CSS class name to the element.

    • hey Joe, Thanks for your help here.

    • brilliant. spent an hour or so online looking exactly for this. thank you.

    • Also spent awhile looking and finally found it here! Thanks, just what I needed.

      My category descriptions are quite long, so I had to make one change in bfa_hor_cats.php to get it to remove the category description from the menu title attribute.

    • neil

      This is really useful. Is there a way to add to this so that if a tag is selected so a list of posts for a tag is displayed, the tag title can be displayed instead of a category title?

    • Hi Neil. If haven’t tested this yet but off the top of my head, try making these substitutions in the code:

      is_category() –> is_tag()
      single_cat_title() –> single_tag_title()
      category_description() –> tag_description()

      Let me know if that works.

    • Thanks Joe, sorry what I meant was to have both, so if the page is a cat. page the original code will function but if it’s a tag page the substitute code will function instead. I had already tried the substitution you suggested tacked on to the end of the original code but I guess it needs some kind of OR syntax. I don’t speak php unfortunately!

    • Hi Neil, see the elseif page in the PHP manual.

      Basically you need something like:
      if (is_category()) {
      // do category stuff
      } elseif (is_tag()) {
      // do tag stuff
      }

      Hope that helps!

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>