我正在尝试使用
为此页面上的每个帖子显示分类术语<?php foreach(get_the_terms($wp_query->post->ID, 'stock') as $term) echo $term->slug; ?>
我之前在体型课中使用过这个,所以我可以更好地设置页面样式,但我不确定为什么它在这里不起作用...
任何人都可以帮忙吗?
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<?php $catquery = new WP_Query( 'cat=10&posts_per_page=10' ); while($catquery->have_posts()) : $catquery->the_post(); ?>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<div class="container">
<a data-toggle="collapse" class="collapsed" data-parent="#accordion" href="#collapse<?php echo $i; ?>" aria-expanded="true" aria-controls="collapseOne">
<h4 class="panel-title">
<?php the_title(); ?><div class="stock-level"> <?php foreach(get_the_terms($wp_query->post->ID, 'stock') as $term) echo $term->slug; ?></div>
</h4></a>
</div>
</div>
<div id="collapse<?php echo $i; ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-7 col-md-7 col-lg-7 recycled-image">
<?php echo the_post_thumbnail(); ?>
</div>
<div class="col-xs-12 col-sm-5 col-md-5 col-lg-5">
<h1><?php the_title(); ?></h1>
<p><?php the_content(); ?></p>
</div>
</div>
</div>
</div>
</div>
</div>
<?php $i++; endwhile; ?>
答案 0 :(得分:0)
如果这是一个存档页面而不是使用$wp_query->post->ID
的单个页面,则不会返回存档中所有帖子的ID。
您必须执行以下操作:
$args = array('YOUR POST ARGS');
$posts = get_posts($args);
foreach ($posts as $post ) {
setup_postdata( $post );
foreach(get_the_terms(get_the_ID(), 'stock') as $term){
echo $term->slug.'<br />';
}
}