1

我正在尝试从自定义帖子类型显示类别标题及其帖子。我可以显示类别,但它目前列出了自定义帖子区域内的所有帖子,而不是将它们分开到

<?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.' &raquo;</a>';
    echo '</div>';
} 
?>
4

2 回答 2

0

中没有选项taxonomyget_posts()试试这个

'tax_query' => array(
        array(
            'taxonomy' => 'staff',
            'field' => 'slug',
            'terms' => $tax_term->slug
        )
    )
于 2013-05-24T06:40:02.827 回答
0
<?php
    $query = new WP_Query( array( 'post_type' => 'testimonials','posts_per_page' => 10 ) ); //testimonials custom post type
    while($query->have_posts()) : $query->the_post();
?>
<ul>
    <li>
        Category:<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_category(', '); ?></a> 
        <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    </li>
</ul>
<?php endwhile; ?>
于 2015-10-29T06:36:26.040 回答