Within my index.php I have a line of code that shows a summary of a post and the author's first name. I would like to display the first name and last initial.
example: "Barack O."
line of code I have now: echo the_author_meta('first_name');
Within my index.php I have a line of code that shows a summary of a post and the author's first name. I would like to display the first name and last initial.
example: "Barack O."
line of code I have now: echo the_author_meta('first_name');
I tried this :
echo substr($the_author_lastname->last_name, 0, 1);
and
echo substr(the_author_lastname(),0,1);
didnt do anything =(
Try this..
$sep = ' '; // Seperator between first name and last initial (space currently)
$ln_init = the_author_meta('last_name');
echo the_author_meta('first_name') . $sep . $ln_init{0};hm tried that it seemed to to just display the the name like this
ObamaBarack
thanks though.
This is a snippet of my code :
foreach($posts as $post){
setup_postdata($post);
childtheme_post_header();
if(get_post_meta($post->ID, 'full-image', $single = true))
echo '<img class="full-image" src="'.get_post_meta($post->ID, 'full-image', $single = true).'"/>';
else
echo '<img class="full-image" src="'.bloginfo('url').'" />';
echo the_author_meta('first_name');
echo (' ');
echo the_author_meta('last_name');
}
but my latest fix is:
if(strlen($the_author_lastname->lastint) >1){
echo substr(last_lastint(),0,1);
}
else{
last_lastint();
}I'm so sure I've seen this before, I think if I am unable to figure it out maybe I can edit each profile and add a nickname to be "Barack O." and just tell wordpress to display nickname, but I hope it does not come to that.
this worked in my setup (in the normal loop):
<?php echo $authordata->first_name.' '.substr($authordata->last_name,0,1).'.'; ?>
alternatively, using the_author_meta() and get_the_author_meta() :
<?php the_author_meta('first_name'); ?> <?php echo substr(get_the_author_meta('last_name'),0,1); ?>.
(ps: might need some adjustments to keep the output nice if some of the fields are empty)
ALCHYMYTH
youre a genius it worked. I used your alternate method it was just missing a space and the period after the last initial so I changed it a little to this:
<?php echo the_author_meta('first_name'); ?>
<?php echo (' '); ?>
<?php echo substr(get_the_author_meta('last_name'),0,1).'.'; ?>
Thanks you. Thank you. Thank you.
This topic has been closed to new replies.