给客户做的网站首页,在文章列表中原本要显示日期和标题的地方,日期只显示第一个,后面的文章标题显示正常,日期都不显示。
此处我用来显示日期的是一个很普通的WordPress函数:the_date()
查了一下WordPress的官方文档,有这么一段提示:
SPECIAL NOTE: 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) ?> |
注:echo不能去掉,否则不会输出内容。
特别说明 ︰ 当同一天发布多篇文章时,the_date() 只显示的日期的第一篇 (就是 the_date()) 的第一个实例。要重复日期根据同一天发布的文章,你应该使用模板标签 the_time() 或 get_the_date();
admin
2020年4月24日 at 上午6:49暫時沒有遇到這個情況,或者以後會遇到呢,學習一下~