カテゴリーの場合のコード
親カテゴリのIDが分かっている場合、 たとえば親カテゴリのIDが1のとき、
1 2 3 | <?php wp_list_categories( 'child_of=1' ); ?> |
親カテゴリはもちろん記事や子カテゴリによって違うわけです。 なので、親カテゴリデータ受け取り→加工の手順が必要です。
/* 現在のカテゴリ-の取得 */
$cat_now = get_the_category();
$cat_now = $cat_now[0];
/*親カテゴリーのID取得*/
$parent_id = $cat_now->category_parent;
- See more at: http://little.ws/200906/204.html#sthash.GAtaZEJG.dpuf
全部まとめると
1 2 3 4 5 6 | <?php $cat_now = get_the_category(); $cat_now = $cat_now [0]; $parent_id = $cat_now ->category_parent; ?> <?php wp_list_categories( "title_li=&child_of=$parent_id" ); ?> |
引用
http://little.ws/200906/204.html