Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress-在博客文章中创建指向独立作者档案的链接_Php_Wordpress - Fatal编程技术网

Php Wordpress-在博客文章中创建指向独立作者档案的链接

Php Wordpress-在博客文章中创建指向独立作者档案的链接,php,wordpress,Php,Wordpress,我们正在Wordpress中开发一个博客,遇到了一些我们在实现上遇到困难的功能 我们的客户希望能够在博客文章中提到博客用户,这将把最终用户带到提到的作者档案。示例如下: “我们最近与我们的最新团队成员Pete Smith进行了交谈”或“我们最近与我们的最新团队成员@Pete Smith进行了交谈” 如果你要点击皮特的名字,它会把你带到website.com/authors/petesmith 我知道Wordpress在评论部分内置了提及功能,但有没有办法在实际的博客文章中实现这一点 很抱歉,我不

我们正在Wordpress中开发一个博客,遇到了一些我们在实现上遇到困难的功能

我们的客户希望能够在博客文章中提到博客用户,这将把最终用户带到提到的作者档案。示例如下:

“我们最近与我们的最新团队成员Pete Smith进行了交谈”
“我们最近与我们的最新团队成员@Pete Smith进行了交谈”

如果你要点击皮特的名字,它会把你带到
website.com/authors/petesmith

我知道Wordpress在评论部分内置了提及功能,但有没有办法在实际的博客文章中实现这一点


很抱歉,我不能在这个问题上包含任何代码,这里没有任何东西可以向大家展示。

您可以在函数中使用类似的内容。php:

add_filter('the_content', 'the_content_func');

function the_content_func($content) {
    $ret = preg_replace_callback ( "/(@[A-Za-z]+)/",
        function ($match) {
            $authorName = mb_substr($match[0], 1);
            $author = get_user_by('slug', $authorName);
            if ( ! empty( $author ) )
                return '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '">' . $author->display_name . '</a>';
            else
                return $authorName;
        },
    $content);
    return $ret;
}
add_filter('the_content'、'the_content_func');
函数的内容函数($content){
$ret=preg_replace_回调(“/(@[A-Za-z]+)/”,
函数($match){
$authorName=mb_substr($match[0],1);
$author=get_user_by('slug',$authorName);
如果(!空($author))
返回“”;
其他的
返回$authorName;
},
$content);
返回$ret;
}
我假设@symbol后面的文本是作者的slug,因此在过滤器中我搜索给定的作者,如果找到了,则输出带有显示名称的相应作者配置文件链接。否则,我只输出不带@symbol&URL的字符串


如果我误解了您的目标,请随意修改preg_replace_callback的内部函数,$match[0]包含从帖子内容中找到的带@符号的用户slug。

您可以在函数中使用类似的内容。php:

add_filter('the_content', 'the_content_func');

function the_content_func($content) {
    $ret = preg_replace_callback ( "/(@[A-Za-z]+)/",
        function ($match) {
            $authorName = mb_substr($match[0], 1);
            $author = get_user_by('slug', $authorName);
            if ( ! empty( $author ) )
                return '<a href="' . get_author_posts_url( $author->ID, $author->user_nicename ) . '">' . $author->display_name . '</a>';
            else
                return $authorName;
        },
    $content);
    return $ret;
}
add_filter('the_content'、'the_content_func');
函数的内容函数($content){
$ret=preg_replace_回调(“/(@[A-Za-z]+)/”,
函数($match){
$authorName=mb_substr($match[0],1);
$author=get_user_by('slug',$authorName);
如果(!空($author))
返回“”;
其他的
返回$authorName;
},
$content);
返回$ret;
}
我假设@symbol后面的文本是作者的slug,因此在过滤器中我搜索给定的作者,如果找到了,则输出带有显示名称的相应作者配置文件链接。否则,我只输出不带@symbol&URL的字符串


如果我误解了您的目标,请随意修改preg_replace_callback的内部函数,$match[0]包含从帖子内容中找到的带@符号的用户slug。

以下是作者存档页面的代码

<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a>

以下是作者存档页面的代码

<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ), get_the_author_meta( 'user_nicename' ) ); ?>"><?php the_author(); ?></a>


这不是链接到作者页面,这是从帖子正文内部链接到其他作者个人资料这不是链接到作者页面,这是从帖子正文内部链接到其他作者个人资料谢谢,我想我们可以处理这个问题。那么上面的代码将只是浏览所有内容并用链接替换@?午饭后我会给你打一针,让你知道我的情况:)谢谢你,我想我们可以一起做。那么上面的代码将只是浏览所有内容并用链接替换@?午餐后,我会给你一个机会,让你知道我是如何相处的:)简单地在名字上创建一个链接,地址是从作者页面的URL复制的,怎么样?虽然这样做会有效,不是所有客户办公室的用户都会理解如何用这种方式来做。简单地在从作者页面的URL复制地址的名称上创建一个链接如何?虽然这样做可行,但不是所有客户办公室的用户都会理解如何用这种方式来做