admin管理员组文章数量:1323224
I'm trying to display the first and last name of an author without having to change the "Display publicly as..." setting. Problem is, I can only seem to find solutions for either or, or at best display/nice/nickname. I would like to display the full name no matter what the user/author has chosen to "Display publicly as".
Ideally I'd like to combine the below if possible.
get_the_author_meta('first_name')
and
get_the_author_meta('last_name')
Any help would be appreciated!
EDIT (FINAL CODE):
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$full_name = '';
if( empty($fname)){
$full_name = $lname;
} elseif( empty( $lname )){
$full_name = $fname;
} else {
//both first name and last name are present
$full_name = "{$fname} {$lname}";
}
$nicknames = "";
//get_author_role()
$userjob = get_cimyFieldValue(get_the_author_meta('ID'), 'JOBTITLE');
//$userjob = "";
ob_start();
coauthors_links();
//coauthors_firstname();
$authornames = $full_name;
ob_end_clean();
if (empty($authornames)) {
$authornames = get_the_author();
} else {
$userjob = NULL;
}
$linkpre = "<a href='/author/".get_the_author_meta('user_nicename')."'>";
$linkpost = "</a>";
if (custom_author_byline("") !== ""){
$authornames = get_the_author();
$linkpre = $linkpost = "";
$userjob = NULL;
}
//echo coauthors_links();
//get_the_author_meta("nickname")
echo "<p class='authormet'>By ".$linkpre.$authornames.$linkpost."</p><br/><p class='authormet'>".$categories_list." | ".get_the_date()."</p>";
I'm trying to display the first and last name of an author without having to change the "Display publicly as..." setting. Problem is, I can only seem to find solutions for either or, or at best display/nice/nickname. I would like to display the full name no matter what the user/author has chosen to "Display publicly as".
Ideally I'd like to combine the below if possible.
get_the_author_meta('first_name')
and
get_the_author_meta('last_name')
Any help would be appreciated!
EDIT (FINAL CODE):
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$full_name = '';
if( empty($fname)){
$full_name = $lname;
} elseif( empty( $lname )){
$full_name = $fname;
} else {
//both first name and last name are present
$full_name = "{$fname} {$lname}";
}
$nicknames = "";
//get_author_role()
$userjob = get_cimyFieldValue(get_the_author_meta('ID'), 'JOBTITLE');
//$userjob = "";
ob_start();
coauthors_links();
//coauthors_firstname();
$authornames = $full_name;
ob_end_clean();
if (empty($authornames)) {
$authornames = get_the_author();
} else {
$userjob = NULL;
}
$linkpre = "<a href='/author/".get_the_author_meta('user_nicename')."'>";
$linkpost = "</a>";
if (custom_author_byline("") !== ""){
$authornames = get_the_author();
$linkpre = $linkpost = "";
$userjob = NULL;
}
//echo coauthors_links();
//get_the_author_meta("nickname")
echo "<p class='authormet'>By ".$linkpre.$authornames.$linkpost."</p><br/><p class='authormet'>".$categories_list." | ".get_the_date()."</p>";
Share
Improve this question
edited Feb 7, 2013 at 15:38
kallekillen
asked Feb 7, 2013 at 15:19
kallekillenkallekillen
1583 gold badges4 silver badges15 bronze badges
1
|
2 Answers
Reset to default 11Try the following:
<?php
$fname = get_the_author_meta('first_name');
$lname = get_the_author_meta('last_name');
$full_name = '';
if( empty($fname)){
$full_name = $lname;
} elseif( empty( $lname )){
$full_name = $fname;
} else {
//both first name and last name are present
$full_name = "{$fname} {$lname}";
}
echo $full_name;
?>
The get_the_author
can directly be used to display the name of the author. There are few settings to be done on the admin for this:
- Under the user settings add make sure you have the first and last name fields filled up.
- After that see for the
Display name publicly as
options and select whichever format you want the name to be shown. - Click save and refresh your page.
本文标签: phpGet author full name
版权声明:本文标题:php - Get author full name 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065368a2418800.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
the_author_meta( 'display_name' )
. – Fabien Snauwaert Commented May 15, 2017 at 16:30