我有一个网站,一篇文章有多个作者,文章后需要多个作者框bios。
我以前使用过get\\u the\\u author\\u meta()将用户的社交媒体超链接作为作者描述下的可点击图标,但当与合作作者使用foreach循环时,只使用第一作者的社交媒体链接。
我尝试将参数$author\\u id更改为$coauthor\\u id,但这似乎不起作用。使用get\\u,作者只需拉取所有css精灵图标,而不带超链接。
我知道原始的get\\u the\\u author\\u meta()代码是有效的,因为它仍然在单作者帖子上运行,我似乎无法将其转换为与合作作者兼容。
<?php
$twitter = get_the_author_meta(\'twitter\', $author_id);
$facebook = get_the_author_meta(\'facebook\', $author_id);
$googleplus = get_the_author_meta(\'googleplus\', $author_id);
$linkedin = get_the_author_meta(\'linkedin\', $author_id);
$instagram = get_the_author_meta(\'instagram\', $author_id);
$youtube = get_the_author_meta(\'youtube\', $author_id);
$email = get_the_author_meta(\'email\', $author_id);
global $post;
$author_id=$post->post_author;
foreach( get_coauthors() as $coauthor ): ?>
<div class="author-box">
<div class="author-avatar">
<?php echo get_avatar( $coauthor->user_email, \'96\' ); ?>
</div>
<div class="author-description">
<h5 class="author vcard"><span class="fn"><a href="<?php echo get_author_posts_url( $coauthor->ID, $coauthor->user_nicename ); ?>"><?php echo $coauthor->display_name; ?></a></span></h5>
<p class="author-bio"><?php echo $coauthor->description; ?></p>
</div>
<div class="author-box-social-icons">
<?php
if(!empty($email)) {
echo \'<a title="Email" href="mailto:\'.$email.\'" id="author-social-email"></a>\';
}
if(!empty($instagram)) {
echo \'<a title="Instagram" href="\'.$instagram.\'" id="author-social-instagram"></a>\';
}
if(!empty($youtube)) {
echo \'<a title="YouTube" href="\'.$youtube.\'" id="author-social-youtube"></a>\';
}
if(!empty($linkedin)) {
echo \'<a title="Follow me on LinkedIn" href="\'.$linkedin.\'" id="author-social-linkedin"></a>\';
}
if(!empty($googleplus)) {
echo \'<a title="Follow me on Google Plus" href="\'.$googleplus.\'" id="author-social-googleplus"></a>\';
}
if(!empty($twitter)) {
echo \'<a title="Follow me on Twitter" href="https://twitter.com/\'.$twitter.\'" id="author-social-twitter"></a>\';
}
if(!empty($facebook)) {
echo \'<a title="Follow me on Facebook" href="\'.$facebook.\'" id="author-social-facebook"></a>\';
}
?>
</div>
<div class="clear"></div>
</div><!-- .entry-author co-author -->
<?php endforeach;?>
最合适的回答,由SO网友:Sally CJ 整理而成
这些位于foreach
回路:
$twitter = get_the_author_meta(\'twitter\', $author_id);
$facebook = get_the_author_meta(\'facebook\', $author_id);
$googleplus = get_the_author_meta(\'googleplus\', $author_id);
$linkedin = get_the_author_meta(\'linkedin\', $author_id);
$instagram = get_the_author_meta(\'instagram\', $author_id);
$youtube = get_the_author_meta(\'youtube\', $author_id);
$email = get_the_author_meta(\'email\', $author_id);
所以(去掉它,然后)尝试使用
$coauthor->ID
具有
get_the_author_meta()
像这样:
<div class="author-box-social-icons">
<?php
if( $email = get_the_author_meta( \'email\', $coauthor->ID ) ) {
echo \'<a title="Email" href="mailto:\'.$email.\'" id="author-social-email"></a>\';
}
if( $instagram = get_the_author_meta( \'instagram\', $coauthor->ID ) ) {
echo \'<a title="Instagram" href="\'.$instagram.\'" id="author-social-instagram"></a>\';
}
if( $youtube = get_the_author_meta( \'youtube\', $coauthor->ID ) ) {
echo \'<a title="YouTube" href="\'.$youtube.\'" id="author-social-youtube"></a>\';
}
if( $linkedin = get_the_author_meta( \'linkedin\', $coauthor->ID ) ) {
echo \'<a title="Follow me on LinkedIn" href="\'.$linkedin.\'" id="author-social-linkedin"></a>\';
}
if( $googleplus = get_the_author_meta( \'googleplus\', $coauthor->ID ) ) {
echo \'<a title="Follow me on Google Plus" href="\'.$googleplus.\'" id="author-social-googleplus"></a>\';
}
if( $twitter = get_the_author_meta( \'twitter\', $coauthor->ID ) ) {
echo \'<a title="Follow me on Twitter" href="https://twitter.com/\'.$twitter.\'" id="author-social-twitter"></a>\';
}
if( $facebook = get_the_author_meta( \'facebook\', $coauthor->ID ) ) {
echo \'<a title="Follow me on Facebook" href="\'.$facebook.\'" id="author-social-facebook"></a>\';
}
?>
</div>