显示作者注册日期

时间:2021-04-18 作者:Morshed Alam Sumon

在作者档案中,我想以以下格式显示作者注册日期:

2021 01月16日

我找到了以下代码:

$user_ID = $post->post_author;
echo the_author_meta( \'user_registered\', $user_ID );
但其输出格式为:

2021 01月16日10:40:52

我怎样才能去掉时间,得到我想要的格式?

我使用的是日期格式F j, Y

1 个回复
最合适的回答,由SO网友:Abhik 整理而成

重新格式化而不是剥离怎么样?

//Get post author ID
$post_author_id = get_post_field( \'post_author\', $post->ID );

//Get the registration date
$registered_date = get_the_author_meta( \'user_registered\', $post_author_id );

//Convert to desired format
$output = date( \'F j, Y\', strtotime($registered_date));

//Echo
echo $output;

相关推荐

使用Get_the_Date检查帖子是否在6个月前发布

在我的内部content-single 模板,我有一个条件检查,根据帖子的年龄显示文本。这样做的目的是通知访客他们可能正在阅读;“旧”;消息问题是;这个6+ months old 文字显示在只有几天的帖子上,我不明白为什么。This is the code I am using:<?php if ( strtotime( get_the_date() ) < strtotime( \'-1 year\' ) ) { ?>