首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想在显示的wordpress日期上加上100年

问我想在显示的wordpress日期上加上100年
EN

Stack Overflow用户
提问于 2012-03-05 22:35:51
回答 4查看 878关注 0票数 0

我将创建一个“未来”-blogg(类似于博客形式的科幻冒险),并希望显示所有+100年的日期。例如,发布于2012-05-17的帖子应该显示日期2112-05-17。

首先,我以为我可以轻松地将日期设置为2112-05-17,但似乎wordpress无法处理高于2049的日期。

因此,我的下一个想法是修改日期的显示方式。我在考虑在一般情况下修改get_the_date() -template.php,并使其在以后返回日期。

但在这里,我的技能是不够的。我对如何在php中使用日期值一无所知。

get_the_date()看起来像这样:

代码语言:javascript
复制
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年?

任何输入都将被估算为:)

EN

回答 4

Stack Overflow用户

发布于 2012-03-05 22:48:24

Stack Overflow用户

发布于 2012-03-05 22:56:09

假设您的mysql日期格式如下: YYYY-MM-DD

代码语言:javascript
复制
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
}

现在,您可以:

代码语言:javascript
复制
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);
}
票数 0
EN

Stack Overflow用户

发布于 2012-03-06 01:09:02

尝试自定义字段:http://codex.wordpress.org/Custom_Fields

你必须为每个帖子输入+100年的日期,但这样你就不需要依靠php或函数来改变当前的日期了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9568407

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档