到目前为止,您的循环重写很好,但您可以做得更好:
<?php
$at_social_html = \'<ul class="at__social">\';
/* array elements: social-media-name/meta-key => [\'href-before-string\', \'href-after-string\', \'fa-class\'] */
$author_sociables = array(
\'facebook\' => [\'\', \'\', \'fa-fb\'],
\'twitter\' => [\'\', \'\', \'fa-twitter\'],
\'instagram\' => [\'\', \'\', \'fa-instagram\'],
\'google\' => [\'//plus.google.com/\', \'\', \'fa-google-plus\'],
\'pinterest\' => [\'//pinterest.com/\', \'\', \'fa-pinterest\'],
\'tumblr\' => [\'//\', \'.tumblr.com/\', \'fa-tumblr\']
);
/* Loop */
foreach($author_sociables as $key=>$value){
$at_author_meta_value = get_the_author_meta( $key );
if ( $at_author_meta_value ) :
$at_social_html .= \'<li><a target="_blank" class="author__social" href="\'. $value[0] . esc_url( $at_author_meta_value ) . $value[1]\'"><i class="fa \'. $value[2] .\'"></i></a></li>\';
endif;
}
$at_social_html .= \'</ul>\';
echo $at_social_html;