[Resolved] Showing category only on content-single.php, not content.php

Home Forums Support [Resolved] Showing category only on content-single.php, not content.php

Home Forums Support Showing category only on content-single.php, not content.php

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #385595
    Elio Martinez

    Hi,

    I want to show the category of each post in the content-single.php (without the folder icon) and not in the content.php (home, category archives, etc).

    It is possible?

    Thanks.

    #385735
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    So you want to show the current categories attached the post being viewed? Where would you want them to display?

    #385752
    Elio Martinez

    Above the title: category place

    Without the folder icon and with the possibility to change the color of the text.

    #386028
    Tom
    Lead Developer
    Lead Developer

    You could try this:

    add_action( 'generate_before_content', 'tu_add_post_categories' );
    function tu_add_post_categories() {
        if ( is_single() ) {
            $category = get_the_category();
            echo '<div class="entry-meta">' . $category[0]->cat_name . '</div>';
        }
    }
    #386057
    Elio Martinez

    I tried that but with that fix the category is showed in every post (without css) in content.php and content-single.php and I only want that in content-single.php, not in home, category sections, etc.

    #386300
    Tom
    Lead Developer
    Lead Developer

    Oops sorry about that – code updated above πŸ™‚

    #387635
    Elio Martinez

    Hi Tom,

    With that code is solved, but the category is showed without any css. I don’t want the folder icon, but I still want the same old css for the category word so I think that you have to tweak the code again.

    #387714
    Tom
    Lead Developer
    Lead Developer

    Give it a shot now πŸ™‚

    #388877
    Elio Martinez

    Thanks πŸ™‚

    #389131
    Tom
    Lead Developer
    Lead Developer

    No problem πŸ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.