如果想在WordPress文章的末尾,添加文章作者的相关信息,下面一段代码可以方便在文章中添加一个作者的信息框。
将代码添加到当前主题functions.php中:
- wp_author_info_box( ) {
- ;
- ( is_single() && isset( ->post_author ) ) {
- = get_the_author_meta( \’display_name\’, ->post_author );
- ( ( ) )
- = get_the_author_meta( \’nickname\’, ->post_author );
- = get_the_author_meta( \’user_description\’, ->post_author );
- = get_the_author_meta(\’url\’, ->post_author);
- = get_author_posts_url( get_the_author_meta( \’ID\’ , ->post_author));
- ( ! ( ) )
- = \'<div =>关于 \’ . . \'</div>\’;
- ( ! ( ) )
- .= \'<div =>\’ . get_avatar( get_the_author_meta(\’user_email\’) , 90 ) . ( ). \'</div>\’;
- .= \'<div =><a href=>查看 \’ . . \’ 所有文章</a>\’;
- ( ! ( ) ) {
- .= \’ | <a href= target= rel=>网站</a></div>\’;
- } {
- .= \'</div>\’;
- }
- = . \'<footer = >\’ . . \'</footer>\’;
- }
- ;
- }
- add_action( \’the_content\’, \’wp_author_info_box\’ );
- remove_filter(\’pre_user_description\’, \’wp_filter_kses\’);
再将配套的CSS添加到主题样式文件style.css中:
- .author-bio-section {
- : ;
- : ;
- : 100%;
- : 0;
- : ;
- : ;
- }
- .author-name {
- : ;
- : ;
- : 0 0 0;
- }
- .author-details img {
- : ;
- : ;
- : ;
- : 0 0;
- }
最终效果:
源代码出处
暂无评论内容