首页 > PHP, WordPress > wordpress某段时间内的文章数

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;
}

  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: