在父帖子/类别循环中,使用此选项生成子帖子/类别的帖子标题/类别名称列表:
$taxonomy_name = \'category\';
$this_term = get_term_by( \'name\', get_the_title(), $taxonomy_name );
$term_id = $this_term->term_id;
$termchildren = get_term_children( $term_id, $taxonomy_name );
echo \'<ul>\';
foreach ( $termchildren as $child ) {//get the children and search the posts by title
$term = get_term_by( \'id\', $child, $taxonomy_name );
$args = array ( \'post_title\' => $term->name, \'orderby\' => title, \'order\' => ASC);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<li>
<strong><?php the_title(); ?></strong>
<?php the_content(); ?>
</li>
<?php endforeach; ?>
}
echo \'</ul>\';
更新:让我们再试一次。在父帖子/类别循环中使用此。
$taxonomy_name = \'category\';
$this_term = get_term_by( \'name\', get_the_title( get_the_ID() ), $taxonomy_name );
$categories = get_categories( array(
\'orderby\' => \'name\',
\'child_of\' => $this_term->term_ID,
) );
if ( ! empty( $categories ) ) {
foreach ( $categories as $category ) {
$this_post = get_page_by_title( $category->name, OBJECT, \'post\');
echo \'<h3>\' . $this_post ->post_title . \'</h3>\';
}
}