今天给客户调用文章作者,用了好多函数都不显示,如:
<?php the_author(); ?>
<?php the_author_nickname(); ?>
最后通过get_the_author_meta()函数实现,调用如下:
?php echo get_the_author_meta( 'display_name', $post->post_author ) ?>
附带这个函数的参数和用法
用法:
<?php get_the_author_meta( $field, $author_id);?>
$field参数
user_login(用户登录名) user_pass(用户登录密码) user_nicename(用户昵称) user_email(用户邮箱地址) user_url(用户网站地址) user_registered(用户注册时间) user_status(用户状态) display_name(作者显示的名称) nickname(作者昵称) first_name(作者名字) last_name(作者姓氏) description(作者描述) user_level(用户等级) user_firstname(用户名字) user_lastname(用户姓氏) user_description(用户描述)
$author_id为用户的id
举例说明在文章页获取作者昵称:
global $post; $author_id=$post->post_author; //获取用户昵称 $nickname = get_the_author_meta( 'nickname', $author_id);
评论前必须登录!
注册