Support » Fixing WordPress » Displaying Subcategories and Siblings of Custom Post Types and Custom Taxonomies

Viewing 1 replies (of 1 total)
  • 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??

    <?php
      $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>
       <?php
        // Sub-Categories
        } elseif ($parent->term_id && sizeof($children) == 0) {
          echo 'YOURE INSIDE A SUB-CATEGORY';
          $subterm = get_queried_object();
          $tax = 'yourtaxonomy_type';
          $parents = $subterm->parent;
          $term_id = $subterm->term_id;
            echo "<ul>";
            wp_reset_postdata();
            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.
      }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Displaying Subcategories and Siblings of Custom Post Types and Custom Taxonomies’ is closed to new replies.