Support » Themes and Templates » PHP – Separate returned values with space?

  • I am using this code to output the child category slugs that fall within a particular parent category.

    <?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(5, $childcat)) { echo $childcat->slug; }} ?>

    The problem is that when there is more than one category, they are all inserted as one word – I need to separate them with a space. My guess is that I need to use implode for this (?), but I’m not quite sure how to implement it.

    Any ideas?

Viewing 1 replies (of 1 total)
  • Michael


    Forum Moderator

    if you don’t mind an extra space at the end, try:

    <?php foreach((get_the_category()) as $childcat) { if (cat_is_ancestor_of(5, $childcat)) { echo $childcat->slug . ' '; }} ?>
Viewing 1 replies (of 1 total)
  • The topic ‘PHP – Separate returned values with space?’ is closed to new replies.