In today's content is king era, how to effectively manage and monetize high-quality content is the focus of many website operators.Especially for websites that provide membership services, paid courses, or exclusive information, it is particularly important to accurately control the content access permissions of different users.AnQiCMS as an efficient and customizable content management system, provides flexible user group management and VIP system, which can help us easily realize the display or hiding of paid content, thus better for content distribution and revenue management.
Deep Understanding of AnQiCMS User Groups and Permission Management
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 user group.This is not only for managing backend operation permissions, but also for finely controlling 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 that we can set certain specific content to be accessible only by paying or becoming a VIP member, and it can be linked to the user group levels we set.When the user attempts to access this content, the system will decide whether to directly display the content, show a partial preview, or prompt the user to upgrade or purchase, based on the user group they belong to and the set permission rules.
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, category, tags, and other conventional information, AnQiCMS also provides the "document reading level" (ReadLevel)or by custom fields to achieve more flexible permission settings.
- Using the built-in "Reading Level":If the system 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, a high-level tutorial may require VIP level 1, and an industry report may require level 2 of a gold member.The user must reach or exceed this level to access the full content.
- Extending permissions through custom fields:AnQiCMS flexible content model allows us to add custom fields to specific content models (such as articles, products). We can make use of this feature to create such as
is_paid_content(Boolean value, indicating whether it is paid content)、required_vip_level(Number, indicating the required VIP level) orallowed_user_groups(Multi-select, related to the group ID of users allowed to access) and other fields. These custom fields provide infinite possibilities for refined control over content permissions.
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.
The implementation of front-end template: Dynamic display and hide
AnQiCMS uses Django template engine syntax, providing rich template tags and filters, making it intuitive and powerful to implement permission control on the front-end. We can combinearchiveDetail(Document details tag)、userDetail(User details tag) anduserGroupDetail(User group details tag), in conjunction withiflogical judgment tag, to construct content display logic.
We take a common scenario as an example: When a user is not logged in or has insufficient level, they can only see the summary of paid content and upgrade prompts; whereas, a logged-in user with sufficient level can view the full content.
Suppose 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 and the detailed data of the currently logged-in user.Then, we extracted the minimum access level required from the custom fields of the document.{% if %}/{% else %}Structure implements dynamic display of content: if the level is sufficient, the full content is displayed; otherwise, a short preview of the content is displayed, and corresponding prompts and operation entry (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:
- Hierarchical membership system:We can set different levels of members (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, offering a partial free preview can attract users to pay to unlock the full version.
- Content package sales:Pack a series of content related to a topic, set as exclusive for a senior user group, and sell it in the form of a content package.
- Limited time free/trial:Combine marketing activities, temporarily lower 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
In short, AnQiCMS provides us with a complete paid content control solution from content publishing to frontend display, through its excellent 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)
Q: If my content is not set
required_vip_levelCustom fields, orReadLevelIs 0, how will it display?Answer: If no permission level is set for the content, 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 (users who are not logged in can also be considered as level 0), so all users will be able to see the full content.This means that the default content of AnQiCMS is public, and access to the content will be restricted only when the reading level is explicitly set.Q: How to guide unlogged-in users to register or log in when they visit paid content?A: In the above template example, when
currentUser.IdDoes not exist (i.e., the user is not logged in) andrequiredLevelWhen greater than 0, it will display specific prompt information, including "login" and "register member