WordPress.org

Ready to get started?Download WordPress

Forums

Category description outside of the loop? (6 posts)

  1. cvfoss
    Member
    Posted 9 years ago #

    Hi everyone. I'm wondering if there is a way to show the category title and description outside of the loop. What I would like to do is when a visitor goes to a category page (e.g. http://www.somesite.com/category/somecategory) the page shows the category title and description as entered in the admin section and then a list of the posts in that category. I am creating a separate template for this. I've looked through the category template tags and most tags either had to be in the loop or you had to hard code the category id into the template. (I dont want to have to create a separate template for each category). I've searched through the forum and couldn't find a similar request. Let me know if you can help. Thanks.

  2. carthik
    Member
    Posted 9 years ago #

    the template tag (function) category_description(category) returns the description for 'category' (a number, the id of the category you are interested in.
    If no parameter is specified, then the description for the currently set category on the the page you are is returned.
    This function only returns the category description and does not display, to display it you will need to 'echo' it.
    In your case,
    <?php echo category_description(); ?>
    should work fine.
    as another example,
    <?php echo category_description('8'); ?>
    would display the description for category with id = 8.
    hope this helps.

  3. cvfoss
    Member
    Posted 9 years ago #

    This is what I'm looking for, but
    '<?php echo category_description(); ?>'
    doesn't seem to return anything unless a parameter is sent with it. The problem I have is that I don't want to hard code a 'category id' into the template as the template will be used for a number of categories.
    Is it possible to get the 'id' from the URI or some other source so I can insert it into the 'category_description()' function?

  4. Anonymous
    Unregistered
    Posted 9 years ago #

    Try:
    <?php echo category_description($_GET['cat']); ?>
    icxn

  5. locomote
    Member
    Posted 9 years ago #

    Is it possible to do this in 1.5? I added this code but nothing happened.

  6. Jax
    Member
    Posted 9 years ago #

    It works in WP1.5.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.