我试图显示作者的名字和姓氏,而不必更改“公开显示为…”背景问题是,我似乎只能找到或的解决方案,或者最好的显示/尼斯/昵称。无论用户/作者选择“公开显示为”什么,我都希望显示全名。
理想情况下,如果可能的话,我想结合下面的内容。
get_the_author_meta(\'first_name\')
以及
get_the_author_meta(\'last_name\')
任何帮助都将不胜感激!
编辑(最终代码):
$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>";
最合适的回答,由SO网友:WP Themes 整理而成
Try 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;
?>