【问题标题】:WordPress blog date functionWordPress博客日期功能
【发布时间】:2009-08-29 07:19:04
【问题描述】:

我正在使用由 Scott Wallick 创建的 WordPress 博客主题。 Here 是他的网站。仅供参考,我使用的是“Barthelme”主题。

无论如何,这个主题打印出日期如下:2009年8月5日显示为“2009 08 05”。我想将显示更改为以下格式:2009 年 8 月 5 日。

我该怎么做?

我在 WordPress 代码中找到了下面的函数。我可以以某种方式更改下面的代码以使其按照我上面的要求进行吗?如果是这样,我应该进行哪些更改?

function barthelme_date_classes($t, &$c, $p = '') {
    $t = $t + (get_option('gmt_offset') * 3600);
    $c[] = $p . 'y' . gmdate('Y', $t);
    $c[] = $p . 'm' . gmdate('m', $t);
    $c[] = $p . 'd' . gmdate('d', $t);
    $c[] = $p . 'h' . gmdate('h', $t);
}

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    尝试以下方法:

    function barthelme_date_classes($t, &$c, $p = '') {
        $t = $t + (get_option('gmt_offset') * 3600);
        $c[] = $p . 'j' . gmdate('j', $t);
        $c[] = $p . 'M' . gmdate('M', $t);
        $c[] = $p . 'Y' . gmdate('Y', $t);
        $c[] = $p . 'h' . gmdate('h', $t);
    }
    

    我只是更改了每个日期元素的存储顺序,并使用了您要求的格式。

    【讨论】:

    • 我试过这个并没有改变任何东西......还有其他想法吗?谢谢。
    【解决方案2】:

    在 Barthelme 主题中,index.php 的第 23 行显示

    <span class="entry-date">
    <abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO'); ?>">
    <?php unset($previousday); printf(__('%1$s', 'barthelme'), the_date('Y m d', false)) ?>
    </abbr>
    </span>
    

    改成

    <span class="entry-date">
    <abbr class="published" title="<?php the_time('Y-m-d\TH:i:sO'); ?>">
    <?php unset($previousday); printf(__('%1$s', 'barthelme'), the_date('j M Y', false)) ?>
    </abbr>
    </span>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 2016-06-09
      • 1970-01-01
      相关资源
      最近更新 更多