<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_19214"> <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-size:20px;font-weight:normal;line-height:28px;">wordpress某段时间内的文章数,具体效果可以到无冷博客查看</span></span> <div class="blockcode"> <div id="code_dh5"><ol> <li>function num_posts($days=1) {//$days就是设定时间一天;</li> <li> global $wpdb;</li> <li> $today = gmdate('Y-m-d H:i:s', time() 3600 * 8);//获取当前的时间</li> <li> $daysago = date( "Y-m-d H:i:s", strtotime($today) - ($days * 24 * 60 * 60) ); //Today - $days</li> <li> $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 "); </li> <li> foreach ($result as $Item) {</li> <li> $post_ID[] = $Item->ID;//已发布的文章ID,写到一个数组里面去</li> <li> }</li> <li> $post_num = count($post_ID);//输出数组中元素个数,文章ID的数量,也就是发表的文章数量</li> <li> $output .= '<a>'.$post_num.'</a>';//输出文章数量</li> <li> echo $output;</li> <li>}</li> </ol></div> <em onclick="copycode($('code_dh5'));">复制代码</em> </div> </h2> </td></tr></table> <div id="comment_19214" class="cm"> </div> <div id="post_rate_div_19214"></div> <br><br>