/* 调用热门文章 */
function _get_hot_views_post($time=1,$limit=10, $mode='', $term_id=0) {
global $wpdb, $post;
$time = date("Y-m-d H:i:s",time()-$time*30*24*3600);
$output = '';
$mode = ($mode == '') ? 'post' : $mode;
$type_sql = ($mode != 'both') ? "AND post_type='$mode'" : '';
$term_sql = (is_array($term_id)) ? "AND $wpdb->term_taxonomy.term_id IN (" . join(',', $term_id) . ')' : ($term_id != 0 ? "AND $wpdb->term_taxonomy.term_id = $term_id" : '');
$term_sql.= $term_id ? " AND $wpdb->term_taxonomy.taxonomy != 'link_category'" : '';
$inr_join = $term_id ? "INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)" : '';
$most_viewed = $wpdb->get_results("SELECT ID, post_date, post_title, (meta_value+0) AS views FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) $inr_join WHERE post_status = 'publish' AND post_password = '' $term_sql $type_sql AND post_date>'$time' AND meta_key = 'views' GROUP BY ID ORDER BY views DESC LIMIT $limit");
return $most_viewed;
}

 

未经允许不得转载

文章标题:wordpress调用热门文章

原文链接:https://zptheme.cn/53.html

发布信息:文章由【子佩主题】发布于:2021年5月27日 16:32:55

修改信息:文章由【子佩主题】修改于:2021年5月30日 23:51:23

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理.
BuRLRc.jpg

欢迎您,新朋友,感谢参与互动!

共有 0 条评论

沙发空余