-
-
Save dirtyarteaga/369144fc3e55ae70382a4af634fae2ee to your computer and use it in GitHub Desktop.
(参考サイト)
http://q.hatena.ne.jp/1382148601
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if($wp_query->queried_object->parent == 0) : | |
$term_id = $wp_query->queried_object->term_id; | |
$taxonomy_name = $wp_query->queried_object->taxonomy; | |
$termchildren = get_term_children( $term_id, $taxonomy_name ); | |
foreach ( $termchildren as $child ) : | |
$taxs[] = $child; | |
endforeach; | |
foreach( $taxs as $tax_slug) : | |
// 次行はタームIDからターム(カテゴリー)の名前を取得しています。各リストの前に見出しを出力しなくてもいい場合はコメントアウトするか削除してください。 | |
$term_info = get_term_by( 'id', $tax_slug, $taxonomy_name ); | |
$args = array( | |
'post_type' => 'book', | |
'nopaging' => true, | |
'tax_query' => array( | |
array( | |
'taxonomy' => $taxonomy_name, | |
'field' => 'id', | |
'terms' => array( $tax_slug ), | |
) | |
) | |
); | |
query_posts($args); | |
if ( have_posts() ) : ?> | |
// リストの見出しとしてターム名(カテゴリー名)を表示します。 | |
<h2><?php echo $term_info->name; ?></h2> | |
<ul> | |
<?php | |
while ( have_posts() ) : the_post(); ?> | |
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> | |
<?php endwhile; ?> | |
</ul> | |
<?php endif; ?> | |
<?php wp_reset_query(); ?> | |
<?php endforeach; ?><!-- $taxs --> | |
<?php endif; ?><!-- End of If parent category --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment