最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
WordPress根据评论数获取热门文章的例子
时间:2022-06-25 18:36:55 编辑:袖梨 来源:一聚教程网
很多人使用WordPress中经常需要调用WordPress的热门文章功能,获取WordPress热门文章方式有很多,可以按文章的浏览量或者WordPress评论数,本文主要介绍按评论数来获取WordPress的热门文章。
以下将介绍如何通过文章的评论数来获取WordPress热门文章,代码如下:
热门文章
{ 个评论}
get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 6");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
将以上一段代码添加到相应位置,比如添加到single.php文件中,就可以实现文章末尾显示热门文章了。代码中的LIMIT 0, 6为显示文章的数量,可以在此处修改需要的数量。
wordpress获取一周热门文章排行
function mostweek($where = '') {
//获取最近七天的文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostweek'); ?>
wordpress获取一月热门文章排行
function mostmonth($where = '') {
//获取最近30天文章
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
add_filter('posts_where', 'mostmonth'); ?>
相关文章
- 如何交易CUDIS币?2025OKX交易所高效攻略 06-16
- 最好用全球交易所加密货币交易榜单-低手续费现货交易所币安推荐 06-16
- 《白荆回廊》玄戈培养有什么 06-16
- SQD币怎么交易-2025币安交易所新手全攻略 06-16
- 《斗罗大陆:武魂觉醒》混沌之子魂骨搭配方案推荐 06-16
- 最火全球交易所数字资产交易TOP10-去中心化比特币交易所币安推荐 06-16