这是我的当前代码single.php 文件它获取标签。但我想取而代之的是获取类别。我可以用$类别交换$标记吗。
<div class="related-articles">
<div class="related-articles-wrapper">
<?php
$orig_post = $post;
global $post;
$cats = wp_get_post_categories($post->ID);
if ($cats) {
$cat_ids = array();
foreach($cats as $individual_cat) $cat_ids[] = $individual_cat->term_id;
$args=array(
\'category__in\' => $cat_ids,
\'post__not_in\' => array($post->ID),
\'posts_per_page\'=>3, // Number of related posts to display.
\'ignore_sticky_posts\'=>1
);
$my_query = new wp_query( $args );
while( $my_query->have_posts() ) {
$my_query->the_post();
?>
<div class="posts__post" style="background-image: url(<?php echo get_the_post_thumbnail_url($post_id, \'thumbnail\'); ?> ) !important;">
<article>
<a class="posts__post--title" href="<?php the_permalink(); ?>"><h1><?php the_title(); ?></h1></a>
<div class="posts__post--meta">
<p class="posts__post__tag"><a href=""><?php the_category(\' / \'); ?></a></p>
<p class="posts__post__timestamp"><i class="fa fa-clock-o" aria-hidden="true"></i><?php echo time_ago(); ?></p>
</p>
</div>
</article>
</div>
<? }
}
$post = $orig_post;
wp_reset_query();
?>
</div>
</div>