web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. seo教程
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站

wordpress如何在每篇文章未尾自动添加作者等信息

334 ℃
     

wordpress如何在每篇文章未尾自动添加作者等相关信息,下面web建站小编给大家详细介绍一下具体代码!

打开主题下的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');

相关样式根据自己的喜好编辑~

wordpress建站如何利用mysql语法批量插入文章

wordpress搭建视频网,视频加载慢怎么解决

wordpress如何实现版本回退

wordpress如何在文章标题上显示置顶标签

wordpress如何在二级目录建站(小编亲测有效)

标签: wordpress建站

上面是“wordpress如何在每篇文章未尾自动添加作者等信息”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_3338.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > wordpress
本文共计1405个字,预计阅读时长10分钟
生活小工具,收录了80多款小工具
上一篇: 阿里巴巴普惠体3.0字体已经更新(最强中文字体)
下一篇: 跨平台划词翻译、截图翻译工具——Pot划词翻译
x 打工人ai神器