我有一个想法,就是将第一个代码与这个解决方案结合起来,这个解决方案列出了来自特定分类单元的帖子:
<?php $terms = get_terms(\'productcategories\');
foreach ($terms as $term) {
$wpq = array (
\'taxonomy\'=>\'productcategories\',
\'term\'=>$term->slug,
\'order\'=>\'asc\',
\'orderby\'=>\'title\');
$query = new WP_Query ($wpq);
echo "$term->name:<br />";
?>
<?php
if ($query->have_posts() ) : while ($query->have_posts() ) : $query->the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title();?></a>,
<?php endwhile; endif; wp_reset_query(); ?>
<?php
echo "<br />";
}
?>
我设法将两者结合起来,因此这是我目前的解决方案。也许不是最好的,但它很有效。
<?php
$term_slug = get_query_var( \'term\' );
$taxonomyName = get_query_var( \'taxonomy\' );
$current_term = get_term_by( \'slug\', $term_slug, $taxonomyName );
$termchildren = get_term_children( $current_term->term_id, $taxonomyName );
foreach ($termchildren as $child) {
$term = get_term_by( \'id\', $child, $taxonomyName );
$wpq = array (
\'taxonomy\'=>$taxonomyName,
\'term\'=>$term->slug,
\'order\'=>\'asc\',
\'orderby\'=>\'title\');
$query = new WP_Query ($wpq);
echo "$term->name:<br />";
?>
<?php
if ($query->have_posts() ) : while ($query->have_posts() ) : $query->the_post(); ?>
<a href="<?php the_permalink();?>"><?php the_title();?></a>,
<?php endwhile; endif; wp_reset_query(); ?>
<?php
echo "<br />";
}
?>