【发布时间】:2017-03-27 14:34:38
【问题描述】:
使用下面的 wp_query 从三个不同类别中提取最新帖子。作为其中的一部分,我想显示适合每篇文章的类别名称,the_category(); 确实实现了这一点,但是它在名称周围放置了 <a> 和 <li> 标记。我只想获取类别的名称?
<?php
$categories = get_categories();
foreach ($categories as $category)
{
}
$args = array(
'cat' => 'article,fitness,recipe',
'posts_per_page' => '3',
);
$query = new WP_Query($args);
if ($query->have_posts())
{
?>
<?php
while ($query->have_posts())
{
$query->the_post();
?>
<article id="post-<?php the_ID(); ?>" class="col">
<h5><?php echo the_category(); ?></h5>
</article>
<?php } // end while ?>
<?php
} // end if
wp_reset_postdata();
?>
【问题讨论】:
标签: php wordpress foreach categories