我正在尝试从自定义帖子类型显示类别标题及其帖子。我可以显示类别,但它目前列出了自定义帖子区域内的所有帖子,而不是将它们分开到
<?php
$taxonomy = 'staff';
$cat_args = array(
'taxonomy' => $taxonomy,
'tax_input' =>$tax_input,
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0
);
$tax_terms = get_terms($taxonomy);
foreach ($tax_terms as $tax_term) {
echo '<div class="categorybox">';
echo '<h4> <a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></h4>';
$args = array(
'post_type' => 'staff',
"singular_label" => "Department",
'numberposts' => 5,
'taxonomy' => $taxonomy->$tax_term,
);
$posts = get_posts($args);
?>
<ul><?php
foreach($posts as $post) {
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
} ?>
</ul><?php
echo '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>View all articles in ' . $tax_term->name.' »</a>';
echo '</div>';
}
?>