wordpress某段时间内的文章数
h2 style=margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px;span style=color:#555555;font-family:Century Gothic, Microsoft YaHei, Verdana;span style=font-si
wordpress某段时间内的文章数,具体效果可以到无冷博客查看
function num_posts($days=1) {//$days就是设定时间一天;
global $wpdb;
$today = gmdate('Y-m-d H:i:s', time() + 3600 * 8);//获取当前的时间
$daysago = date( "Y-m-d H:i:s", strtotime($today) - ($days * 24 * 60 * 60) ); //Today - $days
$result = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_date BETWEEN '$daysago' AND '$today' AND post_status='publish' AND post_type='post' ORDER BY post_date DESC ");
foreach ($result as $Item) {
$post_ID[] = $Item->ID;//已发布的文章ID,写到一个数组里面去
}
$post_num = count($post_ID);//输出数组中元素个数,文章ID的数量,也就是发表的文章数量
$output .= '<a>'.$post_num.'</a>';//输出文章数量
echo $output;
}
- 上一篇:抓取百度排名
- 下一篇:PHP 列出 MySQL 中所有的数据库
精彩图集
精彩文章






