美工学习 发表于 2023-12-1 12:00:03

WordPress 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()这两个函数。于是把原来的
<?php the_date('m-d') ?>改成以下两条的任意一条,即解决问题:
<?php the_time('m-d') ?>
<?php echo get_the_date('m-d', $post_id) ?>这样就可以了
页: [1]
查看完整版本: WordPress the_date() 函数在循环中只输出一次