如何在WordPress中显示今天的日期?

A trend of displaying current date which was started with newspapers has been adapted by many blogs. As more and more users are using WordPress to create magazine style theme, this is just one of the features that can be a great addon to your site. Having a current date looks professional, and it is certainly useful if your articles are dated. You might think that adding a date to WordPress is hard and will require multiple steps, but it is a short and simple method. In this article, we will share a snippet that will allow you to display today’s date in WordPress or any other PHP based website.

从博客开始显示当前日期的趋势已被许多博客所采用。 随着越来越多的用户使用WordPress创建杂志风格的主题,这只是对您的网站的重要补充之一。 具有当前日期看起来很专业,并且如果您的文章已过时,这肯定会很有用。 您可能会认为在WordPress上添加日期很困难,并且需要多个步骤,但这是一种简短的方法。 在本文中,我们将共享一个片段,使您可以在WordPress或任何其他基于PHP的网站中显示今天的日期。

All you need to do is place the following code in a theme file of your choice, most commonly in header.php:

您需要做的就是将以下代码放入您选择的主题文件中,最常见的是放在header.php中


<?php echo date('l jS F Y'); ?>

The above code will display the date in the following format:

上面的代码将以以下格式显示日期:

Thursday, 17th September 2009

2009年9月17日,星期四

If you do not like the formatting above, you can look at the PHP Date Manual for other parameters.

如果您不喜欢上面的格式,则可以查看《 PHP日期手册》中的其他参数。

Now another way to do this is by just extracting your WordPress admin settings. You can go to Settings > General and select the date format in there and simply add this code instead of the above one:

现在,另一种方法是仅提取WordPress管理员设置。 您可以转到设置>常规,然后在其中选择日期格式,然后只需添加以下代码即可代替上面的代码:


<?php echo date(get_option('date_format')); ?>

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-display-todays-date-in-wordpress/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值