WordPress获取热评文章,禁止搜索,自动草稿
来源:程序员人生 发布时间:2014-04-24 17:05:53 阅读次数:2665次
WordPress获取热评文章 禁止搜索 自动草稿 的代码,弄主题时发现新版本有个自动草稿很烦,老是被搜出来,那就眼不见心为静,在第七行加入一句 post_status != 'auto-draft'即可,意为排除自动草稿。
// 获得热评文章
function simple_get_most_viewed($posts_num=10, $days=30){
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
ORDER BY comment_count DESC LIMIT 0 , $posts_num ";
$posts = $wpdb->get_results($sql);
$output = "";
foreach ($posts as $post){
$output .= "<li>• <a href= "".get_permalink($post->ID)."" rel="bookmark" title="".$post->post_title."" >".$post->post_title."</a> - ".$post->comment_count."个评论</li>";
}
echo $output;
}