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