Core Mechanism: User Groups and Content Reading Levels
The core of AnQi CMS's paid content implementation lies in its built-in 'User Group Management and VIP System' as well as the 'Reading Level' setting on the content level.
Firstly, in the background user group management, we can create different user groups, such as "ordinary membersEach user group can be assigned a specific permission level (usually represented by numbers, with higher levels indicating greater permissions).Through this method, we have clearly labeled the user identity.
其次,for each document on the website (including articles, products, etc.), we can specify a 'reading level' when publishing or editing.This reading level determines the minimum user level required to access this content.For example, the reading level of a regular open article may be 0, and the reading level of a senior VIP exclusive article may be set to 5.
When the user accesses the content, the system will compare the user's group permission level and the content's reading level.If the user's permission level reaches or exceeds the content reading level, they will be allowed full access; otherwise, a restricted prompt will be displayed.
Implementation in front-end template: Dynamic display and control
How to dynamically display or hide content on the front-end of a website based on the user's permission level is the key to implementing paid content control.The powerful template tag system of AnQi CMS provides us with great convenience.
Limit the display of complete content
If we want a document to be accessible only to specific VIP users and show a prompt message to ordinary users, we can implement this logic in the template of the document detail page:
Firstly, we need to obtain the login status and permission level of the current visiting user, as well as the reading level of the current content.Auto CMS usually provides this information in the form of variables.archive.ReadLevel,当前登录用户的权限等级为Englishuser.Level,并且可以通过Englishuser.IsLogin判断用户是否已登录。
那么,在模板中控制内容显示的代码片段可能如下所示:English
{% if user.IsLogin and user.Level >= archive.ReadLevel %}
{# 用户已登录且权限足够,显示完整内容 #}
<div class="full-content">
{{ archive.Content|safe }}
</div>
{% else %}
{# 用户未登录或权限不足,显示提示信息 #}
<div class="vip-exclusive-message">
<p>此内容为VIP专属,请<a href="/login">登录</a>或<a href="/vip-upgrade">升级会员</a>以查看完整内容。</p>
{# 也可以在此处显示部分试读内容 #}
{% if archive.Description %}
<p><strong>试读:</strong>{{ archive.Description }}</p>
{% endif %}
</div>
{% endif %}
This code first checks if the user is logged in and whether their permission level is greater than or equal to the content's reading level. If the conditions are met, the full rich text of the content is displayed safely.archive.Content|safeEnsure that the HTML content is parsed correctly). Otherwise, a friendly prompt will be displayed, guiding the user to log in or upgrade.
A unique identifier in the content list
On pages such as article lists and product lists, in order to make it easy for users to identify VIP exclusive content at a glance, we can add a "VIP
{% archiveList archives with type="page" limit="10" %}
{% for item in archives %}
<li class="article-item">
<a href="{{ item.Link }}">
<h3>
{{ item.Title }}
{% if item.ReadLevel > 0 %} {# 如果阅读等级大于0,则认为是VIP或付费内容 #}
<span class="vip-badge">VIP专属</span>
{% endif %}
</h3>
<p>{{ item.Description }}</p>
{# 其他内容信息 #}
</a>
</li>
{% endfor %}
{% endarchiveList %}
By checkingitem.ReadLevelWhether it is greater than 0, we can dynamically add an eye-catching 'VIP Exclusive' tag next to the content title, which not only enhances the visibility of VIP content but also encourages ordinary users to upgrade.
Fine-grained control: Trial reading and VIP content separation
For certain content, we may want to provide a free trial reading and then limit the remaining content. Although the security CMS ofContentThe field is overall by default, but we can achieve it through some strategies:
- Use the 'Summary' field as a sample reading:In the above example, we have shown how to use
archive.Description(Document Summary) as sample content. - Custom content model field:You can add a custom field named "Preview Content" in the content model. When publishing content, fill in the preview part in this new field, and fill in the full paid content.
ContentField. Then, render these two in the template.