使用添加用户联系方式user_contactmethods
在主题中筛选functions.php
或通过插件:
用户联系方式条目存储在wp_usermeta
桌子URL字段是特殊的;它存储在user_url
中的字段wp_users
桌子
// Add user contact methods
add_filter( \'user_contactmethods\',\'wpse_user_contactmethods\', 10, 1 );
function wpse_user_contactmethods( $contact_methods ) {
$contact_methods[\'facebook\'] = __( \'Facebook URL\', \'text_domain\' );
$contact_methods[\'twitter\'] = __( \'Twitter URL\', \'text_domain\' );
$contact_methods[\'linkedin\'] = __( \'LinkedIn URL\', \'text_domain\' );
$contact_methods[\'youtube\'] = __( \'YouTube URL\', \'text_domain\' );
return $contact_methods;
}
输出模板文件中的链接:
<div class="author-box">
<div class="author-image">
<img src="http://blog.blogeto.com/html/images/author_profile.png" alt="">
</div>
<div class="author-description">
<h2>
<!-- AUTHORS NAME --> <?php the_author(); ?>
<!-- <a href="<?php echo get_author_posts_url( get_the_author_meta( \'ID\' ) ); ?>"><?php the_author() ?></a> -->
<?php
// Get the id of the post\'s author.
$author_id = get_the_author_meta( \'ID\' );
// Get WP_User object for the author.
$author_userdata = get_userdata( $author_id );
// Get the author\'s website. It\'s stored in the wp_users table in the user_url field.
$author_website = $author_userdata->data->user_url;
// Get the rest of the author links. These are stored in the
// wp_usermeta table by the key assigned in wpse_user_contactmethods()
$author_facebook = get_the_author_meta( \'facebook\', $author_id );
$author_twitter = get_the_author_meta( \'twitter\', $author_id );
$author_linkedin = get_the_author_meta( \'linkedin\', $author_id );
$author_youtube = get_the_author_meta( \'youtube\', $author_id );
// Output the user\'s social links if they have values.
if ( $author_website ) {
printf( \'<a href="%s"><i class="fa fa-home" aria-hidden="true"></i></a>\',
esc_url( $author_website )
);
}
if ( $author_facebook ) {
printf( \'<a href="%s"><i class="fa fa-facebook" aria-hidden="true"></i></a>\',
esc_url( $author_facebook )
);
}
if ( $author_twitter ) {
printf( \'<a href="%s"><i class="fa fa-twitter" aria-hidden="true"></i></a>\',
esc_url( $author_twitter )
);
}
if ( $author_linkedin ) {
printf( \'<a href="%s"><i class="fa fa-linkedin" aria-hidden="true"></i></a>\',
esc_url( $author_linkedin )
);
}
if ( $author_youtube ) {
printf( \'<a href="%s"><i class="fa fa-youtube" aria-hidden="true"></i></a>\',
esc_url( $author_youtube )
);
}
?>
</h2>
<p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s.Lorem Ipsum is simply dummy text. <a href="#">Read More</a> </p>
</div>
<div class="author-category">
<ul>
<li><a href="">CATEGORY 1</a></li>
<li><a href="">CATEGORY 2</a></li>
<li><a href="">CATEGORY 3</a></li>
<li><a href="">CATEGORY 4</a></li>
<li><a href="">CATEGORY 5</a></li>
</ul>
</div>
</div>