wordpress某段时间内的文章数
时间:2021-07-01 10:21:17
帮助过:18人阅读
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 .= ''.$post_num.'';//输出文章数量
- echo $output;
- }
|