我需要为每个帖子回显类别标签以获得数据过滤器值。有人可以告诉我我在做什么错吗?
<div id="container" class="isotope">
<?php
$args = array(
'post_type' => 'Photos',
);
$_posts = new WP_Query($args);
?>
<?php
if ( $_posts->have_posts() ) : while ( $_posts->have_posts() ) : $_posts->the_post(); ?>
<!-- Here is the issue -->
<div class="grid-item" data-filter="
<?php
$categories = get_the_category(get_the_id());
foreach ($categories as $category){
echo $category->slug.' ';}?>"
>
<a onClick='showDialog()' data-target="#lightbox">
<img src="<?php the_field('image'); ?>" alt="">
</a>
</div>
<?php
endwhile; endif;
?>
</div>
请更改这样的代码
<?php
$categories = get_the_category(get_the_ID());
foreach ($categories as $category){
$slug = $category->slug;
?>
<div class="grid-item" data-filter="<?php echo $slug; ?>">
<?php
}
?>