小工具      在线工具  汉语词典  dos游戏  css  js  c++  java

wordpress标签页面_如何在WordPress中的注释旁边添加用户角色标签

wordpress,java,html,css,php 额外说明

收录于:17天前

WordPress 标签页

我们的一位读者询问是否可以在 WordPress 中的每条评论旁边突出显示用户角色?显示用户角色标签会重视网站上注册用户(特别是作者、编辑和管理员)发表的评论。在本文中,我们将向您展示如何在 WordPress 中的评论旁边轻松添加用户角色标签。

我们的一位读者询问是否可以在 WordPress 中的每条评论旁边突出显示用户角色?显示用户角色标签可以让您网站上的注册用户(尤其是作者、编辑和管理员)发表的评论得到重视。在本文中,我们将向您展示如何在 WordPress 评论旁边轻松添加用户角色标签。

Add user role next to comments in WordPress
为什么在WordPress中的评论作者姓名旁边显示用户角色标签? Why Show User Role Label Next to Comment Author Name in WordPress?

If you 允许用户注册 on your website or run a 多作者 WordPress 网站, then user labels can introduce users to each other based on their 用户角色.

如果您允许用户在您的网站上登记或运行多作者 WordPress 网站 ,则用户标签可以根据用户角色将用户介绍给彼此。

For example, users with the 编辑者用户角色 will show a badge next to their name in comments letting other users know that this comment was made by an editor.

例如,具有编辑者用户角色用户将在评论名称旁边显示一个徽章,以使其他用户知道此评论是由编辑者做出的。

它可以建立用户信任并提高用户对您网站评论的参与度。

它可以建立用户信任并提高用户对您网站上的评论的参与度。

Many WordPress themes only 突出显示帖子作者的评论. They don’t show labels for any other user roles even if other comments are made by registered users or site administrators.

许多WordPress主题仅突出显示帖子作者的评论 。 即使已注册用户或站点管理员发表了其他评论,它们也不会显示任何其他用户角色的标签。

话虽这么说,让我们看看如何在 WordPress 中的评论旁边轻松添加用户角色标签。

话虽如此,让我们看看如何在 WordPress 中的评论旁边轻松添加用户角色标签。

在WordPress中的评论作者姓名旁边添加用户角色标签 Adding User Role Label Next to Comment Author Name in WordPress

This tutorial requires you to add code to your WordPress theme files. If you haven’t done this before, then please take a look at our guide on how to easily 在 WordPress 中复制并粘贴代码.

本教程要求您将代码添加到WordPress主题文件中。 如果您以前没有做过,请查看我们的指南,了解如何轻松地在 WordPress 中复制并粘贴代码

First thing you need to do is add the following code to your theme’s 函数.php file or a 特定于站点的插件.

您需要做的第一件事是将以下代码添加到主题的函数.php文件或具体的在网站的插件中




if ( ! class_exists( 'WPB_Comment_Author_Role_Label' ) ) :
class WPB_Comment_Author_Role_Label {
public function __construct() {
add_filter( 'get_comment_author', array( $this, 'wpb_get_comment_author_role' ), 10, 3 );
add_filter( 'get_comment_author_link', array( $this, 'wpb_comment_author_role' ) );
}

// Get comment author role 
function wpb_get_comment_author_role($author, $comment_id, $comment) { 
$authoremail = get_comment_author_email( $comment); 
// Check if user is registered
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( 'email', $authoremail );
$comment_user_role = $commet_user_role->roles[0];
// HTML output to add next to comment author name
$this->comment_user_role = ' <span class="comment-author-label comment-author-label-'.$comment_user_role.'">' . ucfirst($comment_user_role) . '</span>';
} else { 
$this->comment_user_role = '';
} 
return $author;
} 

// Display comment author                	
function wpb_comment_author_role($author) { 
return $author .= $this->comment_user_role; 
} 
}
new WPB_Comment_Author_Role_Label;
endif;


This function code above 钩子 into WordPress filters used to display comment author name to include user role label.

上面的此功能代码与WordPress过滤器挂钩,该过滤器用于显示评论作者姓名以包括用户角色标签。

您现在可以访问任何带有评论的帖子以查看其实际效果。注册用户发表的评论将在评论作者姓名旁边显示其用户角色。非注册用户发表的任何评论只会显示评论作者姓名。

现在您可以访问任何带有评论的帖子以查看其实际效果。注册用户发布的评论将在评论作者姓名旁边显示其用户角色。非注册用户发表的任何评论只会显示评论作者的姓名。

User role label shown next to their comment

现在我们已经添加了用户角色,是时候对其进行样式设置并使其看起来干净了。

现在我们已经添加了用户角色,是时候对其进行样式设置并使其看起来干净了。

在我们的代码中,我们为每个用户角色添加了一个 CSS 类,因此我们可以使用这些 CSS 类以不同的方式自定义每个用户徽章(即使用不同的颜色等)

在我们的代码中,我们为每个用户角色添加了一个 CSS 类,因此我们可以使用这些 CSS 类以不同的方式自定义每个用户徽章(即使用不同的颜色等)

您可以使用以下示例 CSS 作为起点:

您可以使用以下示例 CSS 作为起点:


.comment-author-label {
    padding: 5px;
    font-size: 14px;
    border-radius: 3px;
}

.comment-author-label-editor {	
background-color:#efefef;
}
.comment-author-label-author {
background-color:#faeeee;
}

.comment-author-label-contributor {
background-color:#f0faee;	
}
.comment-author-label-subscriber {
background-color:#eef5fa;	
}

.comment-author-label-administrator { 
background-color:#fde9ff;
}

您可以根据自己的喜好随意调整 CSS。这是我们的演示网站上的样子:

您可以根据自己的喜好随意调整 CSS。这是我们的演示网站上的样子:

User role badges displayed with their comments

We hope this article helped you learn how to add user role label next to comments in WordPress. You may also want to see our guide on 如何在 WordPress 评论中延迟加载头像.

我们希望本文能帮助您学习如何在WordPress注释旁边添加用户角色标签。 您可能还想查看有关如何在 WordPress 评论中延迟加载头像指南。

If you liked this article, then please subscribe to our YouTube 频道 for WordPress video tutorials. You can also find us on 推特 and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube 频道 WordPress视频教程。 您也可以在推特Facebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-add-user-role-label-next-to-comments-in-wordpress/

WordPress 标签页

. . .

相关推荐

额外说明

信息系统数据同步解决方案

实施数据同步解决方案时,重要的是确保数据同步是安全的、可靠的,并且能够适应系统变化。定期测试和监控数据同步过程,以确保其稳定运行,并随着需求的变化进行适当的调整和优化。 应用场景:信息系统A和信息系统B实现员工数据同步。 API集成: 如果的A系统和B系

额外说明

结构对齐问题(已翻译)

一个结构体变量定义完之后,其在内存中的存储并不等于其所包含元素的宽度之和。 例一: #include <iostream> using namespace std; struct X { char a; int b; double c

额外说明

Spark 流中 dstream 对象 saveAsTextFiles 的问题

利用spark streaming从kafka读取数据,进行流数据的统计分析,最后产生dstream类型的结果集,但是涉及到数据的保存时,遇到了一点小障碍。 我们都知道,spark中普通rdd可以直接只用saveAsTextFile(path)的方式,保

额外说明

Vue —— 进阶 vue-router 路由(一)(嵌套路由、query参数、命名路由、params参数、props配置)

Vue2.x 系列文章目录 内容 参考链接 Vue2.x - 基础 Vue2.x - 基础 Vue2.x - 进阶 Vue2.x - 进阶脚手架 Vue2.x - 高级 Vuex Vuex概念、工作原理、环境搭建、基本使用、getters Vue2.x

额外说明

Java操作hdfs文件系统

前言 在上一篇,我们通过命令行的使用掌握了如何基于hdfs的命令对hdfs文件系统的常用操作,本篇将分享如何基于JavaAPI 操作hdfs文件系统 前置准备 默认服务器上的hadoop服务已经启动 本地如果是windows环境,需要本地配置下hadoo

额外说明

rabbitMq消息不可达returnListener的使用

我们使用rabbitMq进行业务解耦,日志记录或者处理高并发场景下的业务等,但在某些场景下,由于exchange、bindKey、routingKey没有设置正确,导致我们发送给交换器(exchange)的消息,由于没有正确的RoutingKey可能会存

额外说明

js未知数加已知数的结果数,三者的每个数字不重复

条件:两个三位数相加,结果是4位数,且所有数的每个数字都不能重复,a+284=c,求a和c? var a,b=284,c; for(var a=102;a<=987;a++){ c=a+b; var a_arr=a.toString().split(""

额外说明

【Zap】日志重复打印问题

环境:Go1.18.2 windows/amd64 zap:go.uber.org/zap v1.7.0 近期,在做项目案例的时候,发现使用zap作为日志时,相同的日志内容重复输出,这些天,深入分析了一下zap的源码,发现了该问题出现的原因,现在总结一下

额外说明

【云原生 • Kubernetes】k8s功能特性、k8s集群架构介绍

目录(k8s集群搭建先导篇) 一、Kubernetes 的特性/功能 二、Kubernetes 集群架构介绍 1. master node 节点 2. worker node 节点 三、Kubernetes 核心概念 1. Pod 2. Controll

ads via 小工具