希望这段代码能对您有所帮助。。。
$right_now = gmdate("Y-m-d");
$qstr = "
SELECT wposts.*
FROM $wpdb->posts wposts,
(select postid, sum(pageviews) pageviews
from $pageviews_table
where day >= \'$right_now\' - INTERVAL 30 DAY
group by postid) pv
WHERE wposts.post_status = \'publish\'
AND wposts.post_type = \'post\'
AND wposts.ID = pv.postid
AND wposts.post_date >= \'$right_now\' - INTERVAL 30 DAY
ORDER BY pv.pageviews DESC
LIMIT 10
";
$max_most_read = 5; // Number of "most read-spots"
$posts = $wpdb->get_results($qstr);
if ($posts) {
$i = 0;
foreach ($posts as $post) {
setup_postdata($post);
if ($i < $max_most_read) {
$category = get_the_category();
$i++;
}
}
}