In today's content is king era, how to effectively manage and monetize high-quality content is a focus of many website operators.It is particularly important to precisely control the content access permissions of different users for websites that provide membership services, paid courses, or exclusive information.AnQiCMS as an efficient and customizable content management system provides flexible user group management and VIP system, which can help us easily implement the display or hiding of paid content, thereby better managing content distribution and revenue management.

Understand the user group and permission management of AnQiCMS in depth

One of the core strengths of AnQiCMS is its powerful user group management function.The system allows us to create different user groups and define unique permission levels for each group.This is not just for managing the background operation permissions, but also for fine-grained control over the access to the front-end content.By dividing users into different levels such as ordinary users, VIP users, gold members, etc., we can determine what content they can see and how the content is presented based on the privileges of these user groups.

The built-in VIP system is the key to controlling paid content.It means we can set certain specific content to be 'paid' or 'exclusive member' to access, and it can be linked with the predefined user group level.When a user tries to access this content, the system will decide whether to display the content directly, show a partial preview, or prompt the user to upgrade or purchase based on the user group they belong to and the permission rules set.

Tightly associate content with user group permissions

To implement the display or hide of paid content in AnQiCMS, you first need to associate the content with user group permissions. This is mainly reflected in the content publishing and editing stages.

When we publish or edit a document, in addition to filling in the title, content, categories, tags, and other conventional information, AnQiCMS also provides the document reading level ofReadLevel)or by using custom fields to implement more flexible permission settings.

  1. Using the built-in "Reading Level":If the system has a built-in "Reading Level" feature, we can set a minimum reading level for each document.For example, the reading level of a common article may be 0, an advanced tutorial may require VIP level 1, and an industry report may require level 2 of gold member.Users must reach or exceed this level to access the full content.
  2. To extend permissions through custom fields:AnQiCMS's flexible content model allows us to add custom fields for specific content models (such as articles, products). We can utilize this feature to create such asis_paid_content(Boolean value, indicating whether it is a paid content) orrequired_vip_level(Number, indicating the required VIP level) orallowed_user_groups(Multiple selection, associated with the user group ID that is allowed to access) and other fields. These custom fields provide unlimited possibilities for the refinement of content permission control.

Once the content is marked as requiring specific permissions to access, the next step is how to dynamically display or hide this content on the website front end based on the actual permissions of the user.

Implementation of front-end template: Dynamic display and hide

AnQiCMS uses the Django template engine syntax, providing rich template tags and filters, making it intuitive and powerful to implement frontend permission control. We can combine witharchiveDetail(Document detail tag),userDetail(User detail tag) anduserGroupDetail(User group detail tag),配合ifLogical judgment tag, to build content display logic.

We take a common scenario as an example: when a user is not logged in or does not have enough level, they can only see the summary of paid content and upgrade prompts; while a user who is logged in and has enough level can see the full content.

Assuming we are on the document detail page, and the document has a custom field namedrequired_vip_levelwhich represents the minimum membership level required to access this content.

{# 假设我们正在文档详情页,已获取当前文档详情 archive #}
{% archiveDetail currentArchive with name="all" %} {# 获取当前文档的所有详情 #}
{% userDetail currentUser with name="all" %}       {# 获取当前登录用户的所有信息 #}

{% set contentTitle = currentArchive.Title %}
{% set contentDescription = currentArchive.Description %}
{% set fullContent = currentArchive.Content | safe %} {# 完整内容,注意使用 |safe 过滤器避免HTML转义 #}

{# 从自定义字段中获取访问该内容所需的最低VIP等级。
   这里假设自定义字段名为 'required_vip_level',且值为整数。
   如果字段不存在,可以设置一个默认值,例如0,表示无限制。 #}
{% set requiredLevel = 0 %}
{% archiveParams customParams with id=currentArchive.Id sorted=false %}
    {% if customParams.required_vip_level.Value %}
        {% set requiredLevel = customParams.required_vip_level.Value | integer %}
    {% endif %}
{% endarchiveParams %}

{% set currentUserLevel = 0 %} {# 默认未登录用户等级为0 #}

{% if currentUser.Id %} {# 判断用户是否已登录 #}
    {% userGroupDetail userGroup with id=currentUser.GroupId %} {# 获取当前用户的用户组信息 #}
    {% set currentUserLevel = userGroup.Level %} {# 获取当前用户组的等级 #}
{% endif %}

{# 开始判断内容显示逻辑 #}
{% if currentUserLevel >= requiredLevel %}
    {# 当前用户等级满足或超过所需等级,显示完整内容 #}
    <h1 class="content-title">{{ contentTitle }}</h1>
    <div class="content-description">{{ contentDescription }}</div>
    <div class="full-content-body">
        {{ fullContent }}
    </div>
{% else %}
    {# 用户等级不足或未登录,显示预览和提示 #}
    <h1 class="content-title">{{ contentTitle }} (会员专属)</h1>
    <div class="content-description">
        {{ contentDescription | truncatechars:200 | safe }} {# 显示部分描述作为预览,并确保安全输出 #}
        <p class="preview-more">...</p>
    </div>
    <div class="membership-prompt">
        {% if currentUser.Id %}
            <p>您当前的会员等级是 <strong>{{ currentUserLevel }}</strong>,此内容需要 <strong>{{ requiredLevel }}</strong> 级会员才能查看完整版。</p>
            <p>
                <a href="/member-upgrade" class="btn btn-primary">立即升级会员</a>
                <a href="/member-center" class="btn btn-secondary">前往会员中心</a>
            </p>
        {% else %}
            <p>此为会员专属内容,请登录后查看,或升级至 <strong>{{ requiredLevel }}</strong> 级会员。</p>
            <p>
                <a href="/login" class="btn btn-primary">登录</a>
                <a href="/register" class="btn btn-secondary">注册会员</a>
            </p>
        {% endif %}
    </div>
{% endif %}

In this template code, we first retrieve all the information of the current document as well as the detailed data of the currently logged-in user.Next, we extracted the minimum access level required from the custom fields of the document.By comparing the current user level with the required level, we use{% if %}/{% else %}The structure implements dynamic content display: if the level is sufficient, the full content is displayed; otherwise, a brief preview of the content is displayed, and corresponding prompts and operation entries (such as login, registration, or upgrading to a member) are provided based on the user's login status.

Content operation strategy and advanced application

This ability of AnQiCMS brings great flexibility to content operation:

  • Tiered membership system:We can set different levels of membership (such as ordinary members, silver members, gold members), each level corresponds to exclusive content that can be accessed.
  • Free trial and paid unlock: For high-quality paid content, you can offer a free preview to attract users to pay for the full version.
  • Content bundle sales:Package a series of themed content, set as exclusive for a certain advanced user group, and sell it in the form of a content package.
  • Limited time free/trial:Combine marketing activities, temporarily reduce the access level of some content, or open limited-time free access to specific user groups.

By customizing the content model, we can even refine permission control to a specific field under a specific model.For example, for a 'Product Details' model, we can set the 'Product Price' to be hidden from a specific user group, so only wholesale user groups can see the wholesale price.

In summary, AnQiCMS provides a comprehensive paid content control solution from content publishing to frontend display through its完善 user group management and flexible template tag system.This not only enhances the commercial value of the website content, but also brings users a more personalized and richer browsing experience.


Frequently Asked Questions (FAQ)

  1. Question: If my content is not setrequired_vip_levelCustom fields, orReadLevelIs 0, how will it display?Answer: If the content has not set any permission level, or the level is 0 (usually representing open to all users), then in the above template logic,requiredLevelThe default value will be 0. Since all userscurrentUserLevelAt least 0 (unlogged users can also be considered as level 0), so all users will be able to see the full content.This means that AnQiCMS default content is public, and content will be restricted from access only when the reading level is explicitly set.

  2. What should be done to guide unlogged-in users to register or log in when they visit paid content?In the above template example, whencurrentUser.IdDoes not exist (i.e., the user is not logged in) andrequiredLevelWhen greater than 0, it will display a specific prompt message, including 'login' and 'register member'