手机
当前位置:查字典教程网 >CMS教程 >WordPress >WordPress显示当前文章同分类下的文章列表
WordPress显示当前文章同分类下的文章列表
摘要:因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高PVwordpress显示当前文章同分类最新文章列表:在想要...

因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高PV

wordpress显示当前文章同分类最新文章列表:

在想要显示的地方添加以下代码:

<?php

/*

single page?show current category articles

*/

?>

<?php

if ( is_single() ) :

global $post;

$categories = get_the_category();

foreach ($categories as $category) :

?>

<li id="<?php $category->term_id;?>-posts">

<h2><?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

*/

?>

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

【WordPress显示当前文章同分类下的文章列表】相关文章:

WordPress 显示文章摘要方法 详细篇

wordpress 显示文章日期的方法

Wordpress实现自带的侧边栏和自定义的侧边栏同时存在的方法

wordpress评论者链接在新窗口中打开的方法

WordPress数据库备份的方法:WordPress管理区的管理菜单

WordPress搜索结果按浏览量排序的实现方法

wordpress文章标题为空时其它内容代替的方法

修改WordPress链接顺序和排序的方法

WordPress 文章摘要功能实现代码

Wordpress自定义函数控制文章标题长度

精品推荐
分类导航