WordPress the_date() 函数在循环中只输出一次的问题

本站所有文章均为博主人工写作,绝无AI辅助成分,请放心参阅。

给客户做的网站首页,在文章列表中原本要显示日期和文章标题的地方,日期只显示第一个,后面的文章标题显示正常,日期都不显示。
the_date

此处我用来显示日期的是一个很普通的WordPress函数:the_date()
查了一下WordPress的官方文档,有这么一段提示:
“When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.”

意思是the_date()在同一个页面(同一篇文章)中,只输出一次,如果要重复输出日期,你需要用the_time() 或者 get_the_date()这两个函数。于是把原来的

1
<?php the_date('m-d') ?>

改成以下两条的任意一条,即解决问题:

1
2
<?php the_time('m-d') ?>
<?php echo get_the_date('m-d', $post_id) ?>

本站所有文章均为原创,欢迎转载,请注明文章出处:https://blog.brain1981.com/665.html。百度和各类采集站皆不可信,搜索请谨慎鉴别。技术类文章一般都有时效性,本人习惯不定期对自己的博文进行修正和更新,因此请访问出处以查看本文的最新版本。

关注我们的微信公众号-JennyStudio 本站记录了近几年的工作中遇到的一些技术问题和解决过程,“作品集”还收录了本人的大部分作品展示。除了本博客外,我们的工作室网站 – JennyStudio,内有更多作品回顾和展示。
您也可以扫描左边的二维码,关注我们的微信公众号,在微信上查看我们的案例。

1 关于 “WordPress the_date() 函数在循环中只输出一次的问题” 的评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注