WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] single_cat_title (3 posts)

  1. ozgression
    Member
    Posted 6 years ago #

    Hi Everyone,

    I am looking for a way to display a post's single_cat_title on the homepage (Eaxctly how <?php single_cat_title(); ?> does in the archives).

    Each post only has one category, so any way of just outputting the post's category name on the homepage would be great. How can I do this?

    FYI, <?php the_category(', ') ?> doesn't do what I want, I do not want to link to the category, merely display the name of the category in text.

    Any help you could give me would be amazing. I have searched the support forums but haven't found an answer as of yet.

    Thanks...

  2. whooami
    Member
    Posted 6 years ago #

    inside the loop? outside the loop? You failed to say.

    http://codex.wordpress.org/Template_Tags/get_the_category

  3. ozgression
    Member
    Posted 6 years ago #

    Hey thanks. I actually found that and was going to post the solution here incase someone else needed it one day.

    I think I was using it within the loop and used the following code:

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

    Worked. A. Treat.

Topic Closed

This topic has been closed to new replies.

About this Topic