wordpress单个文章页面的侧边栏如果还是显示和首页,分类页面一样的文章就没什么意思了。下面的代码是显示文章所属分类的文章列表,这样可以让访问者可以方便查看相关文章。回头再改改,看看能不能在分类页面上显示最受欢迎的文章。
添加下列代码在合时的位置即可
/*
single page?show current category articles
*/
?>
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<?php echo $category->name; ?>
$posts = get_posts('numberposts=5&category='. $category->term_id);
foreach($posts as $post) :
?>
endforeach; endif ; ?>
/*
end show current category articles
*/
?>