WordPress.org

Ready to get started?Download WordPress

Forums

check if single post belongs to certain category ... if true - add related posts (3 posts)

  1. Percept
    Member
    Posted 8 years ago #

    Hi,

    my problem is very simple, I can't seem to get the category name of a post in a single string format.
    There's the_category() function which returns a list of all the categories as links. Now what I need is the category of the post as plain text (no link). The posts will always belong to exactly ONE category.

  2. Kafkaesqui

    Posted 8 years ago #

    This bit of PHP will display the name of the (first or only) category for a post:

    <?php
    $category = get_the_category();
    echo convert_chars($category[0]->cat_name);
    ?>

  3. Percept
    Member
    Posted 8 years ago #

    Exactly what I needed, Thanks a lot !

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags