我正在尝试遍历帖子列表并将其显示为类别作为标题。我很成功,唯一让陷入困境的是echo $ category-> name;似乎什么也没产生。我若添加回声“aaa”。 $分类 - >名称; “aaa”出现了。
<?php
$args = array(
'type' => 'cpt_referenzen',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'number' => '',
'taxonomy' => 'taxonomy');
$categories = get_categories( $args );
foreach ($categories as $category) {
?><h2><?php echo $category->name; ?></h1><?php
$args = array( 'post_type' => 'cpt_referenzen', 'cpt_tax_referenz' => $category->slug, 'posts_per_page' => 30, 'orderby' => 'date' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?><p>- <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p><?php
endwhile;
}
?>