How to set user group permissions to control access and display specific content for different users?

Calendar 👁️ 67

In website operations, providing differentiated content access permissions and display effects for different users is crucial for improving user experience, realizing content monetization, and even internal management efficiency.The powerful user group management function of AnQiCMS was born to solve this pain point, allowing us to flexibly divide user groups and finely control the content they can see and operate.

Understanding AnQiCMS user group management

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

Usually, you can find the "User Group Management" entry in the "Administrator Management" or similar user settings area of the AnQiCMS backend.Here, you can create new user groups, specify a unique name for each user group, set permission levels (which is very useful for controlling content access later, such as VIP member 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 automatically assign users to specific groups through the registration process, paid subscriptions, and other methods.

How to control access to specific content for different users

The core of AnQiCMS implementing content access control lies in the combination of front-end template judgment logic and background 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 has provided a series of flexible template tags, allowing you to easily implement these judgments in templates. Among them,userDetailThe tag can help you get detailed information about the current user, including their group ID;userGroupDetailThe tag can retrieve the detailed settings of the user group based on the user group ID or level, such as the permission level. CombinedifLogic judgment tags, 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. First, throughuserDetailTag to obtain the user group ID of the currently logged-in user.
  2. Then, useuserGroupDetailTag, to further obtain the user group of the user group ID obtained.Level(Permission level).
  3. Finally, useifTags will link user permission levels with contentReadLevel.

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

A simplified but practical template logic might look something 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 %}

In this way, 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

Related articles

How to use the anti-crawling feature to protect the display integrity of original content?

In the era of the explosion of digital content, the value of original content is increasingly prominent.For website operators who have invested a lot of effort in creating websites, how to effectively protect the display integrity of these original contents and avoid malicious collection and plagiarism has become an important issue.AnQiCMS (AnQiCMS) is an efficient and secure website building tool that is built with powerful anti-crawling functions, helping us better maintain the originality of our content.Why Original Content Protection is Crucial?Original content is the core asset of a website, it is not only the key to attracting users and enhancing brand influence

2025-11-08

How to batch update content in the background to quickly adjust the display results of the website?

With the explosive growth of internet content, the management and update efficiency of website content has become a key to operational success.For websites with strong dynamics and large content volume, manual editing line by line is not only time-consuming and labor-intensive, but may also affect the overall performance of the website due to operational errors.AnQiCMS (AnQiCMS) understands the challenges faced by operators, providing a powerful batch update feature that makes the quick adjustment and display optimization of website content more efficient than ever.### One, Core Tool: Full Station Content Replacement and Keyword Management When the website brand name changes, product links are updated

2025-11-08

How to display recommended attributes of documents (such as headlines, sliders) on the website front-end?

In content operation, highlighting important or recommended content in an eye-catching way is the key to improving user experience and the efficiency of content reach.AnQiCMS (AnQiCMS) offers a powerful 'recommendation attribute' feature that allows you to easily mark and manage different types of featured content, such as setting it as a headline article, slideshow display, or other specific recommendations.This article will introduce how to effectively present these recommended attributes of documents on the front page of Anqi CMS website.--- ### One, understand the recommended document properties of Anqi CMS First

2025-11-08

How to specify the content model for a specific category and affect the display of its documents?

AnQiCMS provides excellent flexibility in content management, with the core being the tight integration of content models and categories.Understanding how to specify the content model for a particular category and thereby influence the display of its documents is the key to the efficient operation of a website.This not only helps organize your website content neatly, but also makes the front-end display more diverse, meeting different business needs.### Understanding the relationship between content models and categories First, let's clarify the concepts of 'content model' and 'category' in AnQiCMS

2025-11-08

How to optimize website content display strategy through traffic statistics?

In the wave of today's digital marketing, a website is no longer just a pile of content, but also a bridge for interaction with users.Every click, stay, and even departure of each visitor contains valuable information.How to transform these original data into practical insights, thereby optimizing the website content strategy, which is the key to improving operational efficiency and website value.AnQiCMS as a comprehensive content management system, its built-in traffic statistics tool is an important tool for us to achieve this goal.The traffic statistics and crawler monitoring function provided by AnQiCMS is not just a pile of numerical reports, it is a mirror

2025-11-08

How to use the scheduled publishing feature to control articles to be automatically displayed at a future time?

In content operation, the rhythm and timing of content release are often the key factors determining its effectiveness.Imagine that you have carefully prepared a series of contents, hoping that they will appear on the website at a specific time, such as 9 am every morning, or automatically go online before the upcoming festival activities.Manual operation is not only inefficient but also prone to errors. AnQiCMS (AnQiCMS) understands this need and provides a convenient scheduling publishing function, allowing you to easily plan future content and achieve automated operations.Schedule release

2025-11-08

How to configure resource storage and backup to ensure the security and recoverability of website content?

In daily website operations, the security and recoverability of content are of great importance.Imagine if your website data suddenly disappeared, or if important images failed to display, how much trouble it would cause for operations.AnQiCMS (AnQiCMS) is an efficient content management system that provides many functions to help us manage website resources properly and ensure quick recovery in case of emergencies.This article will delve into how to configure the resource storage and backup mechanism of Anqi CMS to maintain the continuous stable operation of the website.### One

2025-11-08

How does AnQiCMS improve the loading speed and display experience of website content through static caching?

In today's fast-paced digital world, the loading speed of websites and user experience are crucial.A fast-reacting website can not only effectively retain visitors but also improve search engine rankings and bring more exposure to the content.AnQiCMS, as an enterprise-level content management system developed based on the Go language, has always regarded high performance as one of its core goals from its initial design, and has significantly improved the speed of website content loading and display experience through this key technology of static caching.Static caching, in simple terms, is the process of pre-generating static HTML files for a website's dynamic content

2025-11-08