php文章浏览量排名,完美实现wordpress主题文章阅读浏览量排行功能

//本文代码为30天内点击排行榜

//请将此代码放在functions.php文件的<?php和 ?>之间的位置

//编码时请选择专业的编码工具

function mostViewedPostList($mode = ”, $limit = 10, $chars = 0, $display = true) {

global $wpdb, $post;

$views_options = get_option(‘views_options’);

$where = ”;     $temp = ”;

$output = ”;     if(!emptyempty($mode) && $mode != ‘both’) {

$where = “post_type = ‘$mode'”;

} else {         $where = ‘1=1′;     }     $mostViewedPostList = $wpdb->get_results(“SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date > ‘” . date(‘Y-m-d’, strtotime(‘-30 days’)) . “‘ AND $where AND post_status = ‘publish’ AND meta_key = ‘views’ AND post_password = ” ORDER  BY views DESC LIMIT $limit”);

if($mostViewedPostList) {

foreach ($mostViewedPostList as $post) {

$post_views = intval($post->views);

$post_title = get_the_title();             if($chars > 0) {

$post_title = snippet_text($post_title, $chars);

}             $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars);

$post_content = get_the_content();

$temp = stripslashes($views_options['mostViewedPostList_template']);

$temp = str_replace(“%VIEW_COUNT%”, number_format_i18n($post_views), $temp);

$temp = str_replace(“%POST_TITLE%”, $post_title, $temp);

$temp = str_replace(“%POST_EXCERPT%”, $post_excerpt, $temp);

$temp = str_replace(“%POST_CONTENT%”, $post_content, $temp);

$temp = str_replace(“%POST_URL%”, get_permalink(), $temp);

$output .= $temp;

}     } else {         $output = ‘

N/A’.“\n”;

}     if($display) {

echo $output;     } else {         return $output;

} }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值