假如想正在WordPress文章的末尾,增加文章作者的相干信息,上面一段代码能够不便正在文章中增加一个作者的信息框。
将代码增加到以后主题functions.php中:
function wp_author_info_box( $content ) { global $post; // 检测文章与文章作者 if ( is_single() && isset( $post->post_author ) ) { // 猎取作者称号 $display_name = get_the_author_meta( 'display_name', $post->post_author ); // 假如不称号,应用昵称 if ( empty( $display_name ) ) $display_name = get_the_author_meta( 'nickname', $post->post_author ); // 作者的集体信息 $user_description = get_the_author_meta( 'user_description', $post->post_author ); // 猎取作者的网站 $user_website = get_the_author_meta('url', $post->post_author); // 作者存档页面链接 $user_posts = get_author_posts_url( get_the_author_meta( 'ID' , $post->post_author)); if ( ! empty( $display_name ) ) $author_details = '<div class="author-name">对于 ' . $display_name . '</div>'; if ( ! empty( $user_description ) ) // 作者头像 $author_details .= '<div class="author-details">' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '</div>'; $author_details .= '<div class="author-links"><a href="'. $user_posts .'">查看 ' . $display_name . ' 一切文章</a>'; // 反省作者正在集体材料中能否填写了网站 if ( ! empty( $user_website ) ) { // 显示作者的网站链接 $author_details .= ' | <a href="' . $user_website .'" target="_blank" rel="nofollow">网站</a></div>'; } else { // 假如作者不填写网站则没有显示网站链接 $author_details .= '</div>'; } // 正在文章前面增加作者信息 $content = $content . '<footer class="author-bio-section" >' . $author_details . '</footer>'; } return $content; } // 增加过滤器 add_action( 'the_content', 'wp_author_info_box' ); // 容许HTML remove_filter('pre_user_description', 'wp_filter_kses'); 再将配套的CSS增加到主题款式文件style.css中: .author-bio-section { background: #fff; float: left; width: 100%; margin: 10px 0; padding: 15px; border: 1px dashed #ccc; } .author-name { font-size: 15px; font-weight: bold; margin: 0 0 5px 0; } .author-details img { float: left; width: 48px; height: auto; margin: 5px 15px 0 0; }
以上就是若何正在WordPress 文章未尾主动增加一个作者信息框的具体内容,更多请存眷资源魔其它相干文章!
标签: WordPress wordpress教程 wordpress自学 wordpress技术
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。