在header.php文件中获取作者注册日期

时间:2014-09-01 作者:RailsTweeter

我有一些在头中执行的代码。php如下:

  if (is_author()) {
      $curauth = (isset($_GET[\'author_name\'])) ? get_user_by(\'slug\', $author_name) : get_userdata(intval($author));
      $date = $curauth->user_registered;
  }
我试图通过几种不同的方式从代码中获取此用户信息,但似乎根本无法获取用户对象本身。它为空。

我在想,在调用用户对象的这个阶段,用户对象可能不可用,但Wordpress准确地进入is\\U author()代码是基于确定当前页面是作者模板。

我做错了什么?

1 个回复
SO网友:Robert hue

如果您在作者页面或循环中使用此选项,那么您可以简单地使用此选项。

echo the_author_meta( \'user_registered\' );
这将输出作者的注册日期。

因此,您的函数将变为。

if ( is_author() ) {
    $curauth = ( isset($_GET[\'author_name\']) ) ? get_user_by( \'slug\', $author_name ) : get_userdata( intval($author) );
    $date = the_author_meta( \'user_registered\' );
}

结束

相关推荐

MANAGE_USERS_CUSTOM_COLUMN筛选器触发的函数不起作用

我正在尝试添加一个自定义列un users。php,但它保持为空。我已经成功地在用户管理页面中添加了一列,在我的主题函数中使用了此代码。php文件:function add_user_test_column( $columns ) { $columns[\'test1\'] = \'Test\'; return $columns; } add_filter( \'manage_users_columns\', \'add_user_test_column\