
WordPress React开发项目初学者指南
the_date ( $format = '', $before = '', $after = '', $echo = true )
the_date – 这个函数用来显示一个文章或页面的日期。它有几个参数,允许自定义输出,如日期格式和是否链接到该日期的档案页。
显示或检索当前文章的写作日期(每个日期一次)。
只有当当前文章的日期与前一个文章的日期不同时,才会输出日期。
也就是说,在循环中显示的每一天的文章只显示一个日期列表,即使该函数为每个文章调用了几次。
HTML输出可以用’the_date’来过滤。日期字符串的输出可以用’get_the_date’来过滤。
function the_date( $format = '', $before = '', $after = '', $echo = true ) { global $currentday, $previousday; $the_date = ''; if ( is_new_day() ) { $the_date = $before . get_the_date( $format ) . $after; $previousday = $currentday; } /** * Filters the date a post was published for display. * * @since 0.71 * * @param string $the_date The formatted date string. * @param string $format PHP date format. * @param string $before HTML output before the date. * @param string $after HTML output after the date. */ $the_date = apply_filters( 'the_date', $the_date, $format, $before, $after ); if ( $echo ) { echo $the_date; } else { return $the_date; } }