php - 为什么我不能在使用 WordPress 的 if 语句中使用 the_time() 函数?

标签 php wordpress

我试图将当前月份保存为一个变量,然后根据该值,我希望它显示月份的全名。当我在函数中使用 the_time() 时,它会自动将其输出,这是我不想要的。

代码如下:

$month = the_time('M');
if($month == 'Aug') { echo 'August'; }

如何将 the_time('M') 的值保存在变量中以在 if 语句中使用而不回显该值?

顺便说一句,我知道我可以使用 the_time() 函数来回显月份的全名,但我将其用作测试。基于 the_time() 是什么,我想显示与月份对应的不同图像。

最佳答案

How can I save the value of the_time('M') in a variable to use in an if statement without it echoing out the value?

使用get_the_time().

Wordpress 中的每个 the_... 函数都有一个 get_the_... 等效函数,它将返回值而不是回显它。

关于php - 为什么我不能在使用 WordPress 的 if 语句中使用 the_time() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7266783/

相关文章:

javascript - 如何在刷新页面时停止重置 JavaScript 计时器

PHP RSA key 创建

wordpress - 将页面映射到 WordPress 中的子域

带有 ssl 和反向代理的 WordPress (nginx)

PHP bindParam 似乎不适用于 PARAM_INT 输出参数

php - LAMP mcrypt 扩展

php - 在 Woocommerce 中处理管理订单列表上的自定义批量操作

php - 禁用 URL 中的类

php - 更新数据库表行

php - PHPStan 中 undefined variable ,但它在其他地方声明