how to display category descriptions on archive pages? (7 posts)

  1. redbox
    Posted 10 years ago #

    I'm trying to display the category description on the category archive pages, but the tag that I found isn't working.

    I'm using

    <?php /* If this is a category archive */ if (is_category()) { ?>
    <?php category_description(); ?>

    But my description does not appear. Am I doing something wrong?

  2. MichaelH
    Posted 10 years ago #

    Took this from the wp-content/themes/default/archive.php template file:
    <h2 class="pagetitle">Archive for the '<?php echo single_cat_title(); ?>' Category</h2>

  3. redbox
    Posted 10 years ago #

    Thanks for the reply. That shows the title, but I'm trying to add the additional description field.

    The page in codex for category descriptions at http://codex.wordpress.org/Template_Tags/category_description shows what I attempted, but for some reason it's not displaying anything.

  4. moshu
    Posted 10 years ago #

    Because your code doesn't "know" which category's description to display. The Codex page you linked says it has to have a (category) parameter:
    (integer) The numeric category ID for which category description to return. Defaults to current category, if one is set.

    I am not a coder, but I am sure you need to tell/get what the current category is in order to make it work.

  5. redbox
    Posted 10 years ago #

    I tried adding the category code such as (11), but that didn't do anything either. I also hoped that leaving it blank would cause it to default to the current category. Either way, nothing happened. Has anyone else seen this work?

  6. MichaelH
    Posted 10 years ago #

    Didn't try this but how about:
    <?php echo category_description(11); ?>

  7. redbox
    Posted 10 years ago #

    That worked perfect, thanks! I added <?php echo category_description(); ?> and it pulls the description for the current category.

    Thank you :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.