可排除自身.
<?php
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<?php
$posts = get_posts('numberposts=5&category='. $category->term_id.'&exclude='.get_the_ID());
foreach($posts as $post) :
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
<?php
endforeach; endif ; ?>

本文介绍了一种使用PHP实现的博客系统中按文章分类展示同一类别下不同文章的方法。通过获取当前文章的分类并显示该分类下的其他文章,实现了相关推荐的功能。
52

被折叠的 条评论
为什么被折叠?



