• I want to display the category of each post in the beginning of the title, example: “Category – Subject”, “Movies – Spider Man review!” and so on.

    This is probably very easy, but I have been searching for forever and I just can’t find it. I would be forever grateful for any help!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Assuming you only have one category per post this example:

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

    taken from Template_Tags/get_the_category

    Thread Starter robpoke

    (@robpoke)

    thank you! I do not know however where to put this code? I know in Index, home, etc.. but where in the code? because it won’t show up ??

    Thread Starter robpoke

    (@robpoke)

    I got it to work now BUT my titles always breaks into two rows, example:

    Category
    Subject

    Movies
    Batman

    I want it to show up as:

    Category Subject

    is there a way to do this?

    <?php
    foreach((get_the_category()) as $category) {
        $category_name = $category->cat_name;
    }
    echo 'Category ' . $category_name . ' Movies ' . $post->title;
    ?>

    If that doesn’t work, paste your code in a pastebin and report the link back here.

    hey michael i used the same above code, but the categories as such on below the post title dont appear as a link.
    could you assist me in getting that …
    my site : https://advancedrace.com NSFW

    advanceracedotcom – post your code in a pastebin and report the link back here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display category in post title?’ is closed to new replies.