In website operation, providing differentiated content access permissions and display effects for different users is the key to improving user experience, achieving content monetization, and enhancing internal management efficiency.The powerful user group management function of AnQiCMS is specifically designed to solve this pain point. It allows us to flexibly divide user groups and finely control the content they can see and operate.

Understand the user group management of AnQi CMS

In AnQiCMS, user groups can be understood as tags used to classify website visitors, each tag being associated with a set of predefined permissions.For example, you can create different user groups such as 'General Visitor', 'Registered Member', 'VIP Member', 'Internal Staff', etc.The purpose of this grouping is to better manage and distinguish user identities, thereby providing customized services.

通常,您可以在AnQiCMS后台的“管理员管理”或类似的用户设置区域找到“用户组管理”入口。Here, you can create new user groups, specify a unique name for each user group, set the permission level (which is very useful for controlling content access later, such as VIP membership levels being higher than regular members), and even define some additional user group settings.After creating a user group, you can manually assign users to the corresponding group, or allow users to automatically belong to specific user groups through registration processes, paid subscriptions, and other methods.

How to control access to specific content for different users

The core of content access control in AnQiCMS lies in the combination of the front-end template judgment logic and the back-end user group configuration.This means that when a user visits the page, the website will dynamically decide what content to display based on their login status and user group.

AnQiCMS provides a series of flexible template tags, allowing you to easily implement these judgments in templates. Among them,userDetailTags can help you obtain detailed information about the current user, including their group ID;userGroupDetailThe tag can obtain detailed settings of the user group based on the user group ID or level, such as the permission level. CombinedifLogic judgment label, we can build a powerful content access control system.

Scenario one: VIP exclusive content

Assuming you have some high-quality articles or exclusive download resources on your website, you only want VIP members to have full access.You can set a 'reading level' or 'access level' for this content.

When publishing or editing content, AnQiCMS usually allows you to set aReadLevel(reading level). For example, a VIP exclusive article'sReadLevelMay be set to “2” (assuming the ordinary member level is 1, and the VIP member level is 2).

You can design it like this in the front-end template (such as the article detail page):

  1. Firstly,userDetailLabel gets the user group ID of the currently logged-in user.
  2. Then, useuserGroupDetailLabel, based on the obtained user group ID, further obtain the user group's.Level(Permission level).
  3. Finally, useifTags associate user permission levels with contentReadLevelcompare.

If the user's permission level is lower than the content reading level, only the summary of the content will be displayed, and the user will be prompted to upgrade to VIP; if the user's permission level meets the requirements, the complete content will be displayed.

An simplified but practical template logic might look like this:

{% userDetail currentUser with name="Id" %} {# 获取当前用户的ID,如果未登录则为0 #}
{% set userLevel = 0 %} {# 默认访客等级为0 #}

{% if currentUser > 0 %} {# 如果用户已登录 #}
    {% userDetail currentGroupId with name="GroupId" id=currentUser %} {# 获取已登录用户的用户组ID #}
    {% if currentGroupId > 0 %} {# 确保用户组ID有效 #}
        {% userGroupDetail currentGroupLevel with name="Level" id=currentGroupId %} {# 获取用户组的等级 #}
        {% set userLevel = currentGroupLevel %}
    {% endif %}
{% endif %}

{% archiveDetail currentArchive with name="Id" %} {# 获取当前文档的ID #}
{% if currentArchive > 0 %}
    {% archiveDetail archiveReadLevel with name="ReadLevel" id=currentArchive %} {# 获取当前文档的阅读等级 #}

    {% if userLevel >= archiveReadLevel %} {# 如果用户等级高于或等于内容阅读等级 #}
        <h3>{{ archive.Title }}</h3>
        <div>
            {# 显示完整文章内容 #}
            {% archiveDetail with name="Content" %}|safe
        </div>
    {% else %}
        <h3>{{ archive.Title }}</h3>
        <div>
            {# 显示文章摘要 #}
            {% archiveDetail with name="Description" %}
            <p>此为VIP专属内容,请<a href="/login">登录</a>或<a href="/vip-upgrade">升级VIP</a>查看完整版。</p>
        </div>
    {% endif %}
{% else %}
    <p>抱歉,未找到相关内容。</p>
{% endif %}

Through this method, AnQiCMS allows you to easily control the visibility of content at the template level without writing complex backend code.

Scene two: Control the display range of content

You can also control the display range of content based on user groups, in addition to completely restricting access.For example, on some article list pages, you can allow ordinary users to see the title and summary, while registered members can see more details, such as thumbnails or publication time.

This can also be done inarchiveListorcategoryListthe loop of list tags, combined with the above user level judgment to achieve.

{% userDetail currentUser with name="Id" %} {# 获取当前用户的ID #}
{% set userLevel = 0 %}
{% if currentUser > 0 %}
    {% userDetail currentGroupId with name="GroupId" id=currentUser %}
    {% if currentGroupId > 0 %}
        {% userGroupDetail currentGroupLevel with name="Level" id=currentGroupId %}
        {% set userLevel = currentGroupLevel %}
    {% endif %}
{% endif %}

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
                <div>{{item.Description}}</div>
                {% if userLevel >= 1 %} {# 假设注册会员等级为1 #}
                    <div>
                        <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        <span>{{item.Views}} 阅读</span>
                    </div>
                {% endif %}
            </a>
        </li>
    {% endfor %}
{% endarchiveList %}

Scene three: Custom navigation menu or function

User group permissions can control the visibility of content and can also be used to customize the navigation menu or function buttons of the website. For example, you may want to internally