像这样的事情应该会有帮助:
<?php
$post_type = \'animals\';
$tax = \'vertebrate\';
$tax_terms = get_terms($tax);
if ( $tax_terms ) {
foreach ($tax_terms as $tax_term) {
$args = array(
\'post_type\' => $post_type,
"$tax" => $tax_term->slug,
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'caller_get_posts\' => 1,
\'orderby\' => \'title\',
\'order\' => \'ASC\'
);
// $my_query = null; <- REMOVE THIS, YOU DON\'T NEED TO NULL VARIABLE BEFORE ASSIGNING IT\'S VALUE
$my_query = new WP_Query($args);
?>
<?php if ( $my_query->have_posts() ) : ?>
<h2><?php echo esc_html($tax_term->name); ?></h2>\'; <?php // <- YOU SHOULD ESCAPE PRINTED VALUES ?>
<ol>
<?php while ($my_query->have_posts()) : ?>
$my_query->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<?php
// setup_postdata( $post ); <- THERE IS NO NEED TO SETUP_POSTDATA HERE (YOU\'VE ALREADY CALLED the_post() ON QUERY
$type_terms = wp_get_post_terms( $post->ID, \'type\');
if ( $type_terms ) {
echo \'<span>(\'. esc_html($terms[0]->name) .\')</span>\';
}
?>
</li>
<?php endwhile; ?>
</ol>
<?php endif; ?>
<?php
// wp_reset_query(); <- YOU DON\'T CHANGE GLOBAL $wp_query, SO THERE IS NO NEED TO RESET QUERY (ESPECIALLY DON\'T DO THIS FOR EACH $tax_term
}
}
// BUT YOU DO CHANGE GLOBAL $post, SO YOU SHOULD RESET IT\'S VALUE TO BE COMPATIBLE WITH PLUGINS AND SO ON
wp_reset_postdata();
?>
在这种情况下,有序列表(OLs)比段落(P)要好得多(因为这些是按名称排序的动物列表)。