WordPress显示当前文章同分类下的文章列表

  今朝在做模板区的wordpress模板,感受假如当前文章页面侧栏或下面显示的照旧整个网站的最新文章和热门文章在用户体验方面并不是很好,出格是针对网站分类较量多,内容较量杂的网站,因为用户寻找的是相关的文章,不相关的文章是没有多大乐趣看,显示当前文章同分类下的文章列表也能提高网站的pv。

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=http://down.chinaz.com/"<?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=http://down.chinaz.com/"<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php
endforeach; endif ; ?>
<?php
/*
end show current category articles
*/
?>

  以上代码是显示当前文章页面显示该文章地址的分类的最新文章:假如是显示在侧栏,则在sidebar.php文件里添加,假如是显示在文章下面,请在single.php文件里添加。

Wordpress下载:

WordPress v3.5.2 简体中文版下载

WordPress显示当前文章同分类下的文章列表

界面预览

WordPress v4.4.2 英文版下载

WordPress显示当前文章同分类下的文章列表

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/10175.html