I would actually load them into an array:
$author_contact = array(
'email' => get_the_author_meta( 'email' ),
'telephone' => get_the_author_meta( 'telephone' ),
'twitter' => get_the_author_meta( 'twitter' ),
);
Once you have that created, you can iterate through it using a foreach()
loop:
<ul class="author-contact">
<?php
foreach( $author_contact as $contact => $address ) {
if( isset( $contact ) ) {
echo '<li class="contact">' . $address . '</li>';
}
}
?>
</ul>
What this code will do is go through all of those get_author_meta()
values and store them in a single array. Then it will loop through them as the pair $contact
& $address
. So say it was email
and the author’s address was [email protected]
. $contact
would be email
and $adress
would be [email protected]
.
Then it will test to see if there is a value given. So if this particular author does not have their telephone number or a Twitter address entered in, then the key would have null value. isset()
will check to see if there is a value and if so, create the list item. If the value is null
then it will simply skip that and move to the next key in the array.