WordPress.org

Support

Support » Plugins and Hacks » check if single post belongs to certain category … if true – add related posts

check if single post belongs to certain category … if true – add related posts

  • 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Kafkaesqui

    @kafkaesqui

    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);
    ?>

    Exactly what I needed, Thanks a lot !

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘check if single post belongs to certain category … if true – add related posts’ is closed to new replies.
Skip to toolbar