我已经设置了一些自定义帖子类型,并且正在尝试使用 javascript 实现页面过滤器。我设法能够输出第一个签名的类,但我无法让它添加多个类。理想情况下,我不想对类别进行硬编码,因为我将把它交给客户,他们将来会添加更多。
这是我到目前为止所拥有的:
<?php
$loop = new WP_Query( array(
'post_type' => 'portfolio_item',
'order' => 'ASC',
'posts_per_page' => -1
)
);
while ( $loop->have_posts() ) : $loop->the_post();
$cats = wp_get_post_categories($post_id);
echo '<div class="'.implode(" ", $cats).' filter-item pb-3">';
?>
<div class="p-4 border text-center bg-white h-100 rounded">
<a href="<?php echo the_permalink();?>">
<div class="dealer-logo" style="height: 300px">
<img src="<?php echo get_the_post_thumbnail_url($post_id, 'full'); ?>"
class="mb-4 mx-auto object-fit object-cover" style="height: 300px">
</div>
<h3><?php echo the_title(); ?></h3>
<div class="mt-4 pb-3">
<p>Read More</p>
</div>
</a>
</div>
</div>
<?php endwhile;?>
因此,例如,在顶部的“过滤器项目”div 中,我希望看到属于该自定义帖子类型的 2/3 类填充。
我目前只得到与帖子相关的第一堂课。我想我需要将类别放在一个数组中,然后遍历这些。然而,这有点超出我的想象。
任何帮助深表感谢!