You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Elementor Posts组件多作者元数据显示问题求助

解决Elementor Posts组件无法显示PublishPress Authors所有合著者的问题

核心思路

Elementor的Posts组件默认调用WordPress原生单作者函数,而PublishPress Authors提供了get_coauthors()来获取所有合著者。我们只需要用钩子替换Elementor的作者输出即可,绝对不要修改插件或Elementor的核心文件(更新会丢失修改内容)。

操作步骤

方式1:用代码片段插件(推荐,适合编程经验较少的用户)

  1. 安装并激活「Code Snippets」插件
  2. 进入后台「Snippets」→「Add New」
  3. 粘贴下方代码,给片段命名(比如「显示所有合著者」),点击「Save Changes and Activate」

方式2:修改子主题的functions.php

  1. 进入后台「外观」→「主题文件编辑器」,选择当前子主题的functions.php
  2. 在文件最末尾粘贴下方代码(先备份原文件,避免出错)

代码实现

add_filter( 'elementor/posts/author_name', 'display_all_coauthors_elementor', 10, 2 );
function display_all_coauthors_elementor( $author_name, $post ) {
    // 检查PublishPress Authors插件是否激活
    if ( function_exists( 'get_coauthors' ) ) {
        $coauthors = get_coauthors( $post->ID );
        $author_list = array();
        
        // 循环遍历所有合著者,生成带链接的作者名
        foreach ( $coauthors as $coauthor ) {
            $author_list[] = '<a href="' . get_author_posts_url( $coauthor->ID ) . '">' . $coauthor->display_name . '</a>';
        }
        
        // 用逗号分隔多个作者
        return implode( ', ', $author_list );
    }
    
    // 如果插件未激活,返回默认的单作者名称
    return $author_name;
}

代码说明

  • 这段代码通过Elementor的elementor/posts/author_name过滤器,替换了Posts组件的作者输出内容
  • 先检查get_coauthors()函数是否存在(确保插件已激活),再获取当前文章的所有合著者
  • 为每个作者生成指向其个人文章列表页的链接,最后用逗号拼接成字符串返回
  • 如果插件未激活,会自动回退到默认的单作者显示逻辑

验证效果

刷新你的最新文章页面,Elementor Posts组件的作者区域应该会显示所有关联的合著者信息了。

内容的提问来源于stack exchange,提问作者Alex Font

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 12:52:20