• Resolved tianacfor3

    (@tianacfor3)


    I am using the page of posts format narrowing down the post by the category to match the page. For any one post, there can be several categories. At the end of the each post, I want to display the categories that particular post is in.

    I found:
    <?php the_category(' &bull; ') ?>

    That will separate the categories, but the categories are links (I don’t want them to be links)

    Then I found:

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

    Which will only display (not be a link), but it doesn’t use a separator between the categories.

    If I put something in between the ‘ ‘ marks it displays after every category – even if there isn’t another category behind it (i.e. if there was only 1 category, then it still displays that separator).

    I am fairly new to using this, and have been able to find answers to all of my other questions, but can someone please help me out with this?

    I want to display the categories, without them being links, and them have a separator between them when appropriate.

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php $cats='' ;
    foreach((get_the_category()) as $category) {
        $cats=$cats.$category->cat_name . ' &bull; ';}
    $cats = substr($cats,0,-8); echo $cats; ?>

    basically this snippet adds all categories into one long string with the divider inbetween, and then strips the 8 divider characters from the end of the string; and then outputs it.

    Thread Starter tianacfor3

    (@tianacfor3)

    thank you so much – that worked perfect

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

The topic ‘Display Categories on Post with Separators’ is closed to new replies.