如果您希望将帖子类别列为链接,那么您可以了解它。我有一个问题,我希望将一个帖子类别空间列表分隔为div的data-id属性的值。
这是我当前循环的样子:
<?php while ( have_posts() ) : the_post(); ?>
<?php $post_id = the_ID(); $post_categories = wp_get_post_categories( $post_id ); ?>
<div class="box" data-id=" <?php foreach($post_categories as $c){ echo $c; } ?> ">
<?php the_post_thumbnail( array(200,200) ); ?>
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h3><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
不幸的是,结果看起来像Loop visual output
我想这对你们中的一些人来说是明智的,但我无法做到这一点。谢谢你看看吧!
答案 0 :(得分:0)
使用get_the_ID()
返回ID:
wp_get_post_categories( get_the_ID() );