WordPress.org

Ready to get started?Download WordPress

Forums

parents and child categories (1 post)

  1. normaltje
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic