我正在尝试列出我最近的帖子列表,同时显示它们现在属于我的类别
<?php $args = array( 'numberposts' => 30) ;
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li>
<a href="'.get_permalink($recent["ID"]).'" title="Look'.esc_attr($recent["post_title"]).'" > '.$recent["post_title"].'</a> </li> '; } ?>
这会显示帖子,但我希望它也显示类别名称。
任何帮助都会很棒,
谢谢
最佳答案
$cats = get_the_category($recent["ID"]);
$cat_name = $cats[0]->name; // for the first category
您可以在循环中尝试此操作(如果您有多个类别)
$cats = get_the_category($recent["ID"]);
foreach($cats as $cat)
{
echo $cat->name." ";
}
关于WordPress 获取最近的帖子并显示标题和类别名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11488046/