我有一个值数组,其中我想要每个项目的索引/键值,这样我就可以使用该值将其作为一个类应用,以达到样式化的目的。我怎样才能做到这一点呢?
这是我到目前为止所得到的:
$args = array(
'post_type' => array('case'),
'post_status' => array('publish'),
'posts_per_page' => 5
);
$query = new WP_Query($args);
if($query->have_posts()) {
while($query->have_posts() ){
$query->the_post();
?>
<div class="grid-item item--HERE I WANT THE KEY/INDEX VALUE">
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php }
}
我希望输出是这样的:
<div class="grid-item item--1">
...etc etc
https://stackoverflow.com/questions/51812670
复制相似问题