Displaying Subcategories and Siblings of Custom Post Types and Custom Taxonomies (2 posts)

  1. jampafoo
    Posted 2 years ago #

    What I would like to achieve is basically what is on this post :


    But, with Custom Post Types! Can anyone help with this sort of set up?

  2. jampafoo
    Posted 2 years ago #

    So, thanks to this post I have achieved what I need with taxonomy categories and their siblings on the taxonomy-{yourtaxonomy}.php page.

    I am using this code in a sidebar, and call this sidebar on the custom taxonomy page. I am calling it on a single too (single-yourtaxonomy.php). I am trying to get the same results as on the taxonomy page but haven't quite got that yet. I will also be calling it on the archive page (archive-yourtaxonomy.php)! Maybe someone can give me some hints??

      $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); // get current term
      $parent = get_term($term->parent, get_query_var('taxonomy') ); // get parent term
      $children = get_term_children($term->term_id, get_query_var('taxonomy')); // get children
      // Category Views
      if (!is_single()) {
        // Main Categories
        if (!$parent->term_id && sizeof($children) > 0) {
          echo 'YOURE INSIDE A CATEGORY';
           $args = array(
             'child_of' => $term->term_id,
             'taxonomy' => $term->taxonomy,
             'hide_empty' => 1,
             'hierarchical' => true,
             'depth'  => 1,
             'title_li' => ''
           <ul> <?php  wp_list_categories( $args ); ?></ul>
        // Sub-Categories
        } elseif ($parent->term_id && sizeof($children) == 0) {
          $subterm = get_queried_object();
          $tax = 'yourtaxonomy_type';
          $parents = $subterm->parent;
          $term_id = $subterm->term_id;
            echo "<ul>";
            wp_list_categories( array (
              'taxonomy'  => $tax,
              'pad_counts'=> 0,
              'title_li'  => '',
              'child_of'  => $subterm->parent,
            echo "</ul>";
      // Single Views
      } else {
           echo 'YOURE INSIDE A SINGLE';
           //still trying to figure out how to show the single's category and siblings.

Topic Closed

This topic has been closed to new replies.

About this Topic