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;}
复制代码