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

2016-04-13cms教程
55

因为用户寻找的是相关的文章,不相关的文章是没有多大兴趣看,博客吧认为这样也能提高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="<?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
*/
?>

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

相关推荐

网站图片丢失或者获取失败时显示默认图片的办法
当我们的网站时间久了难免会出现图片丢失或者误删,这样文章的图片就无法显示了,会让页面变的很难看。那么当网站图片丢失或者获取失败时如何显示我们设置的默认图片呢,或者默认多张图片随机显示呢。 方法一:当图片调用失败后,会用图片后面设置的默认图片...
2022-10-24 cms教程
71

修改帝国CMS默认提示框样式为layui
修改帝国CMS默认提示框样式为layui,修改文件:e/message/index.php link href="?=$public_r[newsurl]?hmb2019/css/layui.css" rel="stylesheet" type="text/css"div class="layui-container" div class="layui-card" style="width:400px;box-shadow: 1px 1px...
2022-10-20 cms教程
331

WordPress上一篇、下一篇文章链接添加title属性的方法
上一篇、下一篇文章代码: ?php previous_post_link(%link,) ??php next_post_link(%link,) ? 该代码解析出来的代码大概如下: a href= rel=external nofollow rel=external nofollow /aa href= rel=external nofollow rel=external nofollow /a 通过 get_pr...
2017-08-03 cms教程
358

WordPress去除链接添加 Noopener Noreferrer 的教程
WordPress目前在最近的版本中为所有需要新窗口打开的链接都自动添加了新的 noopener noreferrer 属性。noopener noreferrer 属性并不是新发布的标准,但 WordPress 4.7.4 版开始的编辑器默认都会添加该属性。新窗口打开超链接的属性 target=_blank 增加 rel=...
2017-07-31 cms教程
232

dicuz搭建的论坛如何修改改后台地址?
用discuz搭建的论坛,后台默认地址是 域名加 admin.php,很多站长怕网站被黑客攻击,一般黑客会扫描admin文件,然后破解管理员账户登录后台,所以想修改后台的地址。直接修改 admin.php 名并放到其他文件夹里,访问后台用修改过的路径虽然能访问,但是会出错...
2017-07-08 cms教程
364

phpcms筛选功能(经典无错)---汇总网上各种版本!
phpcms的筛选功能,网上有各种版本,但是多多少少都会有点问题,不是很完美,下面我总结网上各种版本,加上自己的研究,得出一个算是比较全的一个资料,既可以分页,也可以分栏目! 第一步:后台添加字段 添加字段: 后台--内容--内容相关设置--模型管理--文...
2017-06-26 cms教程
436