列出您可以使用的名称和描述get_terms(). 这将返回一个包含所有项的数组。例如:
global $post;
$terms = get_terms( array(
\'taxonomy\' => \'item_tags\',
\'hide_empty\' => false,
) );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
echo \'<h2>\' . $term->name . \'</h2>\';
echo apply_filters( \'the_content\', $term->description );
$items = get_posts( array (
\'post_type\' => \'item\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'item_tags\',
\'terms\' => $term->term_id,
),
),
) );
foreach ( $items as $post ) {
setup_postdata( $post );
?>
<div>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
</div>
<?php
}
}
wp_reset_postdata();
}
希望有帮助!