Support » Fixing WordPress » Show parent category.

  • Resolved AlphaCentavr

    (@alphacentavr)


    Hello everybody.
    I have custom post type and taxonomy for this post type. When I go to category page, I display title of current category:
    <?php single_cat_title(); ?>
    And I want display parent category of current category.
    Also I created template for categories of custom post types: taxonomy-sector.php
    How do it?
    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    Try it with this in your taxonomy-sector.php:

    <?php
       $object = get_queried_object();
       // check if term is hierarchical and has a parent
       if(($object->parent > 0) && is_taxonomy_hierarchical($object->taxonomy )) {
         $term = get_term($object->parent, $object->taxonomy );
         echo '<h3><a href="' . get_term_link( $term->name, $object->taxonomy) . '">' . $term->name . '</a></h3>';
       }
    ?>

    Thank you!
    This is help me.

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    You’re welcome. Glad you got it resolved.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show parent category.’ is closed to new replies.