【问题标题】:How to customize Date Format in Wordpress如何在 Wordpress 中自定义日期格式
【发布时间】:2012-04-23 10:27:51
【问题描述】:

我需要在 Wordpress 中自定义日期格式。我知道可以从仪表板

我需要在帖子页面上,月应该有不同的字体样式,而日应该有不同的字体。

【问题讨论】:

  • 这个在主题里改了,看你用哪一个了。
  • 如果我的理解正确,您想对月和日应用不同的样式吗?

标签: php css wordpress html wordpress-theming


【解决方案1】:

如果我正确理解您的问题,一种解决方案是将日期的每个部分包装在不同的跨度类中。因此,每当您想插入日期时,您都会使用以下内容:

<?php the_time('F', '<span class="month">', '</span>'); ?>
&nbsp;
<?php the_time('d', '<span class="day">', '</span>'); ?>

然后你可以在你的 css 中分别定位这些不同的 span 类。

.month {
    font-family:serif;
}
.day {
    font-family:sans-serif;
}

这将输出如下所示的格式:4 月 11 日,其中月份和日期可以根据需要单独设置样式。您可以通过更改传递给the_time() 函数的内容来显示不同的月/日格式。例如,将月份代码更改为 &lt;?php the_time('m', '&lt;span class="month"&gt;', '&lt;/span&gt;'); ?&gt; 将改为输出 Apr 11

有很多不同的配置,这里有更多信息http://codex.wordpress.org/Formatting_Date_and_Time

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 2020-07-08
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多