修改了一下WP的接口文件,弄成未来发布

时间: 2009-10-07 / 分类: wordpress / 浏览次数: 4,139 views / 0个评论 发表评论

主要就是时间和发布状态改变

我的想法是读取数据库中发表文章最晚的时间,然后加上间隔时间再和现在时间比较

如果和比现在时间晚就用这个时间,如果比现在时间早那么就从现在时间开始算起,加个间隔时间得到未来时间

//小货添加
?$oldtime = $wpdb->get_row( “SELECT post_date FROM $wpdb->posts? WHERE post_type = ‘post’ order by post_date desc” );

//转化成一串数字
?preg_match(‘#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#’, $oldtime->post_date , $matches);
?$string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
?
//发表文章间隔时间
$jiangetime=60*60*3;//3小时一篇
//判断是使用读取的时间还是现在的时间
if($string_time+$jiangetime>time()){
??$usetime = gmdate(‘Y-m-d H:i:s’, $string_time + $jiangetime+ get_option(‘gmt_offset’)*3600);//gmt_offset似乎是时区设置
}else{
??$usetime = gmdate(‘Y-m-d H:i:s’, time() + $jiangetime+ get_option(‘gmt_offset’)*3600);//gmt_offset似乎是时区设置
}
//echo “从数据库读取的最迟时间:”.$oldtime->post_date.”<br>转成数字:”.$string_time.”<br>现在时间:”.time().”<br>真正使用时间:”.$usetime.”<br>”;
//小货添加结束

然后在

function ETwp_write_post() {
?global $user_ID,$usetime;

里引入了这个$usetime参数

把发表状态弄成未来

$_POST[‘post_status’] = ‘future’;

再把有关时间的东东去掉

/*
?foreach ( array (‘aa’, ‘mm’, ‘jj’, ‘hh’, ‘mm’) as $timeunit ) {
??if ( !empty( $_POST[‘hidden_’ . $timeunit] ) && $_POST[‘hidden_’ . $timeunit] != $_POST[$timeunit] ) {
???$_POST[‘edit_date’] = ‘1’;
???break;
??}
?}

?if (!empty ( $_POST[‘edit_date’] ) ) {
??$aa = $_POST[‘aa’];
??$mm = $_POST[‘mm’];
??$jj = $_POST[‘jj’];
??$hh = $_POST[‘hh’];
??$mn = $_POST[‘mn’];
??$ss = $_POST[‘ss’];
??$jj = ($jj > 31 ) ? 31 : $jj;
??$hh = ($hh > 23 ) ? $hh -24 : $hh;
??$mn = ($mn > 59 ) ? $mn -60 : $mn;
??$ss = ($ss > 59 ) ? $ss -60 : $ss;
??$_POST[‘post_date’] = sprintf( “%04d-%02d-%02d %02d:%02d:%02d”, $aa, $mm, $jj, $hh, $mn, $ss );
??$_POST[‘post_date_gmt’] = get_gmt_from_date( $_POST[‘post_date’] );

?}
*/

直接用我们生成的时间

$_POST[‘post_date’]=$usetime;
??$_POST[‘post_date_gmt’]=$usetime;

测试通过

发表评论

您的昵称 *

您的邮箱 *

您的网站