WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display category description on single posts within that category (6 posts)

  1. joelwalsh
    Member
    Posted 9 years ago #

    How do I call the category description (of the current post's category) on a post's single page?

    My reason for wanting this is that I have a disclaimer in the category description (for instance, posts about medical subjects should not be taken as medical advice etc.).

  2. joelwalsh
    Member
    Posted 9 years ago #

    Is the category description not part of the "loop" I hear so much about? Does it have to be called "outside the loop" unlike other tags?

  3. skippy
    Member
    Posted 9 years ago #

    You should be able to use category_description() to display the category description. You may specify a category ID. If not specified, the current category will be used.

  4. joelwalsh
    Member
    Posted 9 years ago #

    <?php echo category_description(); ?>

    Works when I supply a category ID number but when it's left blank it doesn't produce anything.

    You can see it here: http://upmarketnewsletters.com/articles/test-opinion/

  5. joelwalsh
    Member
    Posted 9 years ago #

    I figured it out:

    <?php
    foreach((get_the_category()) as $cat) {
    echo $cat->category_description . ' ';
    } ?>

  6. navigadget
    Member
    Posted 8 years ago #

    The above doesn't really work. It displays the main category description at all times.

    So there isn't a way to show the category description without having to hard-code the category number yet.

Topic Closed

This topic has been closed to new replies.

About this Topic