我将创建一个“未来”-blogg(类似于博客形式的科幻冒险),并希望显示所有+100年的日期。例如,发布于2012-05-17的帖子应该显示日期2112-05-17。
首先,我以为我可以轻松地将日期设置为2112-05-17,但似乎wordpress无法处理高于2049的日期。
因此,我的下一个想法是修改日期的显示方式。我在考虑在一般情况下修改get_the_date() -template.php,并使其在以后返回日期。
但在这里,我的技能是不够的。我对如何在php中使用日期值一无所知。
get_the_date()看起来像这样:
function get_the_date( $d = '' ) {
global $post;
$the_date = '';
if ( '' == $d )
$the_date .= mysql2date(get_option('date_format'), $post->post_date);
else
$the_date .= mysql2date($d, $post->post_date);
return apply_filters('get_the_date', $the_date, $d);
}对如何修改它有什么想法吗?所以它在返回之前将日期增加了100年?
任何输入都将被估算为:)
发布于 2012-03-05 22:48:24
发布于 2012-03-05 22:56:09
假设您的mysql日期格式如下: YYYY-MM-DD
function add100yr( $date="2011-03-04" ) {
$timezone=date_timezone_get();
date_default_timezone_set($timezone);
list($year, $month, $day) = split(':', $date);
$timestamp=mktime(0,0,0, $month, $day, $year);
// 100 years, 365.25 days/yr, 24h/day, 60min/h, 60sec/min
$seconds = 100 * 365.25 * 24 * 60 * 60;
$newdate = date("Y-m-d", $timestamp+$seconds );
// $newdate is now formatted YYYY-mm-dd
}现在,您可以:
function get_the_date( $d = '' ) {
global $post;
$the_date = '';
if ( '' == $d )
$the_date .= mysql2date(get_option('date_format'), add100yr($post->post_date));
else
$the_date .= mysql2date($d, add100yr($post->post_date));
return apply_filters('get_the_date', $the_date, $d);
}发布于 2012-03-06 01:09:02
尝试自定义字段:http://codex.wordpress.org/Custom_Fields
你必须为每个帖子输入+100年的日期,但这样你就不需要依靠php或函数来改变当前的日期了。
https://stackoverflow.com/questions/9568407
复制相似问题