wp抢手文章调用方法
wp热门文章调用方法
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// 获得热评文章
function simple_get_most_viewed($posts_num=10, $days=300){ global $wpdb; $sql = "SELECT ID , post_title , comment_count FROM $wpdb->posts WHERE post_type = 'post' AND TO_DAYS(now()) - TO_DAYS(post_date) < $days AND ($wpdb->posts.`post_status` = 'publish' OR $wpdb->posts.`post_status` = 'inherit') ORDER BY comment_count DESC LIMIT 0 , $posts_num "; $posts = $wpdb->get_results($sql); $output = ""; foreach ($posts as $post){ $output .= "\n<li><a href= \"".get_permalink($post->ID)."\" rel=\"bookmark\" title=\"".$post->post_title." (".$post->comment_count."条评论)\" >". $post->post_title."</a></li>"; } echo $output; } ?> |
1
|
<?php simple_get_most_viewed(); ?>
|