Help

Help > Forum > 主题和外观 > 为特定用户组更改帖子的背景颜色

为特定用户组更改帖子的背景颜色

您可以为来自特定用户组的帖子设置不同的背景颜色。例如,您可以将普通用户组中用户的帖子的背景颜色设置为金色,而其他用户的帖子仍使用默认颜色。请按照以下说明进行操作:

  1. 登录您的Website Toolbox账户。
  2. 点击 整合 链接。
  3. 点击 自定义代码 链接。
  4. 复制下面的 HTML 代码并将其粘贴到 论坛头标记 HTML 代码 文本框:
  5. <style>
    .post-body.wt-general-post {
        background-color: #f5efd7;
    }
    .post-author.wt-general-post .post-arrow {
        border-right-color: #f5efd7;
    }
    @media (max-width: 720px) {
        .post-author.wt-general-post {
            background-color: #f5efd7;
        }
    }
    </style>
    <script>
    var groupCustomClass = {
            'GENERAL-GROUP-ID' : 'wt-general-post'
        };
        function changePostBackgroundColor() {
            if(jQ('.post-body-wrapper').length) {
                jQ('.post-body-wrapper .post-body-author .display_name a').each(function( index ) {
                    var postAutherDivId;
                    var postDivId = jQ(this).closest('.post-body').attr('id');
                    if(typeof postDivId != "undefined" && postDivId != "" && postDivId.indexOf('post_list_') > -1) {
                        postAutherDivId = postDivId.replace(/post_list_/g,"post_row_");
                    }
                    if(typeof postAutherDivId != "undefined" && postAutherDivId != "") {
                        var className = jQ(this).attr('class');
                        var classArray = className.split(' ');
                        jQ.each(classArray, function(index, value) {
                          if(typeof value != "undefined" && value != "" && value.indexOf('usergroup') > -1) {
                            var groupid = value.replace(/usergroup/g,"");
                            console.log("=groupid="+groupid+"=postAutherDivId="+postAutherDivId+"=class="+groupCustomClass[groupid]+"=end=");
                            if(typeof groupid != "undefined" && groupid != "" && groupid) {
                                jQ('#'+postDivId+'').addClass(groupCustomClass[groupid]);
                                jQ('#'+postAutherDivId+' .post-author').addClass(groupCustomClass[groupid]);
                                return false;
                            }
                          }
                        });
                    }
                });
            }
        }
        // Change post back ground color when DOM loaded.
        window.addEventListener("DOMContentLoaded", function(){
            changePostBackgroundColor();
        });
        // Change post back ground color when create a post.
        document.addEventListener('replyPosted', function(event) {
            changePostBackgroundColor();
        });
        // Change post back ground color when edit a post.
        document.addEventListener('postEdited', function(event) {
            changePostBackgroundColor();
        });
    </script>
    
  6. 更改颜色代码 #f5efd7 在上面的代码中,所有三个地方都有你需要的那个。#f5efd7 代表蓝色。点击 十六进制码 获取不同颜色的颜色代码。
  7. 取回 用户组的 ID.
  8. 替换文本 普通群组 ID 在上面的代码中,在步骤 6 中检索了用户组的 ID。
  9. 保存 你的更改。

以下是精选帖子的示例:


If you still need help, please contact us.