Support » Fixing WordPress » Can I echo the direct parent of a child category?

  • Hi all!

    First I had a category (say ‘X’) with only one level of child categories beneath it (‘X1′, X2’, ‘X3’, …) , so it was easy to display a link to this child categorie by means of this snippet:

    $sep = '';
    foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(10, $childcat)) {
    echo $sep.'<a class="white" href="'.get_category_link($childcat->cat_ID).'">',$childcat->cat_name,'</a>';
    $sep = ', ';

    But now I have to add another level, so the hierarchy becomes: X -> X1 -> X1a, X1b, X1c, …..

    When I display a post from categoroy X1c, how do I tweak the snippet in such a way that I can display X1 underneath it as a link. I have been trying for hours now, but without success…

    All help would be much appreciated!


  • The topic ‘Can I echo the direct parent of a child category?’ is closed to new replies.