wordpress同类最新文章

今天在折腾主题的时候,想给当前分类下显示最新文章列表。就是显示与文章分类相同的最新文章。看到了prower的新主题prowerv4里面有这个功能。当在文章页面时,显示统一分类文章。代码如下:

<div id="related_post">
<h3><?php $category = get_the_category(); echo $category[0]->cat_name; ?> 下的最新文章</h3>
<?php
if(is_single()){
$cats = get_the_category();
}
foreach($cats as $cat){
$posts = get_posts(array(
'category' => $cat->cat_ID,
'exclude' => $post->ID,
'showposts' => 10,
));
echo '<ul>';
foreach($posts as $post){
echo '<li><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>';
}
echo '</ul>';
}
?>
</div>

标题为“wordpress基础教程下的最新文章”,然后其他的应该很容易看懂的了。

声明: 未经本站许可,谢绝转载!

0 个主题帖 其中:热心观众:0 个, 管理员:0 个

抱歉,评论被关闭