资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

在WordPress文章未尾自动添加一个作者信息框的方法-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联建站是一家专注于成都网站设计、做网站、成都外贸网站建设公司与策划设计,万柏林网站建设哪家好?创新互联建站做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:万柏林等地区。万柏林做网站价格咨询:13518219792

这篇文章主要介绍在WordPress 文章未尾自动添加一个作者信息框的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

如果想在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 = '
关于 ' . $display_name . '
'; if ( ! empty( $user_description ) ) // 作者头像 $author_details .= '
' . get_avatar( get_the_author_meta('user_email') , 90 ) . nl2br( $user_description ). '
'; $author_details .= ''; } else { // 如果作者没有填写网站则不显示网站链接 $author_details .= '
'; } // 在文章后面添加作者信息 $content = $content . '
' . $author_details . '
'; } 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文章未尾自动添加一个作者信息框的方法-创新互联
URL分享:http://cdkjz.cn/article/dhpios.html
返回首页 了解更多建站资讯
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220