복붙노트

[WORDPRESS] WordPress : 분류학 용어의 계층 적 목록

WORDPRESS

WordPress : 분류학 용어의 계층 적 목록

해결법


  1. 1.당신은 $ tactominations를 통과하기 위해 놓쳤습니다

    당신은 $ tactominations를 통과하기 위해 놓쳤습니다

     $subterms = get_terms($taxonomies, array(
          'parent'   => $term->term_id,
          'hide_empty' => false
          ));
    

    코드를 따라보십시오

    function return_terms_index() {
      $taxonomies = array( 
        'taxonomy_name',
      );
    
      $args = array(
        'orderby'           => 'name', 
        'order'             => 'ASC',
        'hide_empty'        => false, 
        'fields'            => 'all',
        'parent'            => 0,
        'hierarchical'      => true,
        'child_of'          => 0,
        'pad_counts'        => false,
        'cache_domain'      => 'core'    
      );
    
      $terms = get_terms($taxonomies, $args);
    
      $return .= '<ul>'; 
    
        foreach ( $terms as $term ) {
    
          // return terms (working)
          $return .= sprintf(
            '<li id="category-%1$s" class="toggle">%2$s <span class="cat-description">%3$s</span>',       
            $term->term_id,
            $term->name,
            $term->description
          );
    
            $subterms = get_terms($taxonomies, array(
              'parent'   => $term->term_id,
              'hide_empty' => false
              ));
    
            $return .= '<ul>';
    
            foreach ( $subterms as $subterm ) {
    
              //return sub terms (not working :( )
              $return .= sprintf(
              '<li id="category-%1$s" class="toggle">%2$s <span class="cat-description">%3$s</span>',       
              $subterm->term_id,
              $subterm->name,
              $subterm->description
              );
    
              $return .= '</li>'; //end subterms li
            }            
    
            $return .= '</ul>'; //end subterms ul
    
          $return .= '</li>'; //end terms li
        } //end foreach term
    
      $return .= '</ul>';
    
    return $return;
    }
    
  2. from https://stackoverflow.com/questions/26732017/wordpress-hierarchical-list-of-taxonomy-terms by cc-by-sa and MIT license