1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | <?php //カテゴリー・タグ情報を取得(slug,アーカイブページでターム名取得,タクソノミー名取得) $term = get_term_by( 'slug' ,get_query_var( 'term' ),get_query_var( 'taxonomy' ) ); ?> <?php //$termにはいってる情報で分岐 if ( $term ->parent ) { // 親IDが入ってれば (子だったら) ?> <!---TOP部分--> <?php //親のIDを取得してターム情報を引き出す。 $ido = $term ->parent; $term2 =get_term( $ido ,get_query_var( 'taxonomy' )); ?> <a href="<?php //子 親のターム情報からターム名とリンクを引き出す。 echo get_term_link( $term2 ->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term2 ->name; ?> </a> <div style= "clear:both" ></div> <!---一覧部分--> <?php wp_list_categories( array ( 'title_li' => '' , 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term ->parent, //親のIDを出力 'hide_empty' => 0, ) ); } else { //親だったらそのまま出力 ?> <!---TOP部分--> <a href="<?php //親 echo get_term_link( $term ->slug,get_query_var( 'taxonomy' )); ?> "> <?php echo $term ->name; ?> </a> <div style= "clear:both" ></div> <!---一覧部分--> <?php wp_list_categories( array ( 'title_li' => '' , 'taxonomy' => get_query_var( 'taxonomy' ), 'child_of' => $term ->term_id, 'hide_empty' => 0, ) ); }?> |