本站想和你分享如何在一篇WordPress文章中显示所有评论者的名字。希望你看完这篇文章后收获很大。大家一起讨论一下。
以场景为例,在文章的适当位置,显示目前有:石、焦厚根、朱逸群、夏等。谁发表了热情的评论,并添加一个锚链接,以引导读者跳转到评论形式,并发送一个热情的评论。
向当前主题函数模板函数添加代码。
function get _ comment _ authors _ list($ id=0,$sep=\’,\’){
$post_id=$id?$ ID : get _ the _ ID();
if($post_id){
$comments=get_comments(array(
post_id\’=$post_id,
状态\’=\’批准\’,
键入\’=\’注释\’,
));
$ names=array();
foreach($ commentas $ comment)活动:慈云数据爆款香港服务器,CTG+CN2高速带宽、快速稳定、平均延迟10+ms 速度快,免备案,每月仅需19元!! 点击查看{
$ name=$ comment-comment _ author;
if($comment-user_id){
$ user=get _ user data($ comment-user _ id);
$name=$user?$ user-display _ name : $ name;
}
$arr=explode(\’,trim($ name));
if(!empty($arr[0])!in_array($arr[0],$names)){
$ names[]=$ arr[0];
}
}
un set($ comments);
$sep=$sep?$sep: \’,\’;
return内爆($sep,$ names);
}
}
add _ short code(\’ comment _ authors _ list \’,\’ comment _ authors _ list _ short code \’);
function comment _ authors _ list _ short code($ atts=array()){
$atts=shortcode_atts(array(
post_id\’=0,
list_sep\’=\’ \’,
),$ atts);
return get _ comment _ authors _ list($ atts[\’ post _ id \’],$ atts[\’ list _ sep \’]);
}使用方法:
首先,用ID: 123称呼文章所有评论者的名字
在模板中使用:
?phpechoget _ comment _ authors _ list(\’ 123 \’);在文章中添加简短代码:
【comment _ authors _ list post _ ID=\’ 123 \’/】其次,把当前文章的所有评论者的名字都叫出来。类似于上面,只需去掉文章ID,适合放在文章正文模板中。
在模板中使用
?phpechoget _ comment _ authors _ list();在文章中添加简短代码:
【comment_authors_list/】看完这篇文章,相信你对一篇WordPress文章中显示所有评论者姓名的实现方法有一定的了解。如果你想了解更多相关知识,请关注本站谢谢阅读!
《显示WordPress某个文章所有评论者名称的实现方法》来自互联网同行内容,若有侵权,请联系我们删除!
还没有评论,来说两句吧...