很多人使用WordPress中经常需要调用WordPress的热门文章功能,获取WordPress热门文章方式有很多,可以按文章的浏览量或者WordPress评论数,本文主要介绍按评论数来获取WordPress的热门文章。
以下将介绍如何通过文章的评论数来获取WordPress热门文章,代码如下:
将以上一段代码添加到相应位置,比如添加到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'); ?>