• Dear WordPress people,

    On my website I have three main categories with a lot of child categories filed under them. I have been searching the forums for code snippits with which I could render the exact child category under which a specific post is filed, with a link to all posts under that child category.


    <?php
    foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(10, $childcat)) {
    echo '' .$childcat->cat_name .'';
    }}
    ?>

    This works very fine, but only when there is only one child category selected in a certain parent category. When there are two childs, the following problem occurs:

    child category Y and child category Z (both filed under parent category X) are rendered under the page as YZ. How can I modify the code above to print them with a certain separator ont eh page?

    All help is welcome! Thanks in advance.

  • The topic ‘parents and child categories’ is closed to new replies.