我希望得到最近4篇帖子的列表,以及该帖子所属的第一个(也是唯一一个)类别的链接。
$args = array(
\'numberposts\' => \'4\',
\'offset\' => \'0\'
);
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {
echo \'<li>\'
\'<a href="\' . get_permalink($recent["ID"]) . \'" class="previous-post-thum">\'
get_the_post_thumbnail($recent["ID"], \'previous-posts-image\')
\'</a>\';
echo \'<p class="previous-cat-date">\'
get_the_time(\'F d,Y\', $recent["ID"])
\'</p>\';
echo \'<a class="previous-post-cat" href="\'
get_category_link($recent["ID"]) . \'">\'
the_category($recent["ID"]) . \'</a>\';
echo \'<p class="previous-post-title"><a href="\'
get_permalink($recent["ID"]) . \'" class="previous-title">\'
$recent["post_title"] . \'</a></p>\';
$excerpt_text = apply_filters(\'the_excerpt\', $recent[\'post_excerpt\']);
$number_of_characters = 350;
echo \'<div class="previous-post-excerpt">\'
substr($excerpt_text, 0, strrpos(substr($excerpt_text, 0, $number_of_characters), " "))
\'...\' . \'</div>\';
echo \'<p class="previous-post-more">\'
\'<a href="\' . get_permalink($recent["ID"]) . \'">Read More</a>\'
\'</p>\'
\'</li>\';
}
除“类别”链接外,此代码有效。