As a senior website operation expert, I am more than happy to discuss with you the subtle points of AnQiCMS (AnQiCMS) in terms of content operation, especially how to achieve fine-grained control of content through its flexible template configuration, such as hiding the 'Previous Article' navigation under specific article types.

Auto CMS provides us with great freedom with its efficient architecture based on the Go language and excellent customizability.In daily content operations, we often hope that the website can intelligently display content, which is both convenient for users to browse and conforms to the business logic of different content types.While the 'Previous/Next' navigation is standard in blogs or news articles, it may not be as suitable in product details, special topic pages, or some special promotional pages, and may even distract users' attention.

UnderstandingprevArchivetags

In the template system of AnQi CMS,prevArchiveIt is a very practical template tag.It is usually used on article detail pages, which can automatically fetch the previous content of the current document on the time or ID sequence and generate the corresponding link and title, facilitating continuous reading for users.

{% prevArchive prev %}
    {% if prev %}
        <a href="{{ prev.Link }}">{{ prev.Title }}</a>
    {% else %}
        <span>没有了</span>
    {% endif %}
{% endprevArchive %}

This code will judge whether the previous article exists.If it exists, display its link and title; otherwise, may display 'No longer available' or simply not display any content.Our goal is to add an additional layer of custom condition judgment on the logic of 'display or not'.

核心思路:条件判断的力量

The template engine of AnQi CMS is similar to Django, providing powerful conditional judgment capabilities, which is the key to our fine-grained control. We can directly access a named variable in the template of each document's detail page.archiveThe global object, it contains all the details of the current document, such as the document ID (archive.Id) and the title (archive.Title)、所属分类ID (archive.CategoryId)、内容模型ID (archive.ModuleId)、even custom fields, etc.

Utilize{% if ... %}tags, we can then determinearchivewhether to display these properties in the objectprevArchivenavigation.

1.Based on the content model (Module ID) for judgment

One of the highlights of AnQi CMS is its flexible content model.We can create different models to manage articles, products, cases, and so on.Assuming we have a 'Article model' (the default ID may be 1) and a 'Product model' (assuming ID 2).We may wish to hide the 'Previous Article' navigation on all product detail pages.

In this case, we can configure it like this in the template:

{# 假设产品模型的ID是2。我们只想在非产品模型下显示“上一篇” #}
{% if archive.ModuleId != 2 %}
    {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">← 上一篇: {{ prev.Title }}</a>
        {% else %}
            <span></span> {# 留空,不显示文本 #}
        {% endif %}
    {% endprevArchive %}
{% endif %}

This code will check the model ID of the current document. If it is not a product model (i.e.archive.ModuleIdNot equal to2),then the 'Previous Article' navigation will be displayed normally. Conversely, if it is a product model, the entire content within the block will not be rendered, thereby cleverly hiding the navigation.ifblock will not be rendered, thereby cleverly hiding the navigation.

2.According to classification (Category ID) to judge

In addition to content models, document classification is also a common way to distinguish content types.Sometimes, we may want to hide the 'Previous Article' navigation for a specific category (such as 'Special Offers', with an ID of 15) and show it normally for all other categories.

The configuration method is similar, just change the judgment condition to Category ID:

{# 假设“特价商品”分类ID是15。我们不想在该分类下显示“上一篇” #}
{% if archive.CategoryId != 15 %}
    {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">← 上一篇: {{ prev.Title }}</a>
        {% else %}
            <span></span>
        {% endif %}
    {% endprevArchive %}
{% endif %}

This method is particularly suitable for scenarios where you have multiple models but only want to disable navigation in specific categories.

3.Using custom fields or recommended properties (Flags)

The Anqi CMS provides highly flexible custom fields and built-in recommended attributes (such asWe can use these properties to make more refined control.

For example, you can set a recommendation attribute of 'Do not display navigation' for certain special articles in the article editing interface in the background, or create a boolean custom field nameddisable_prev_nav.

  • Use recommended attribute (Flag):Assuming we agree that if an article is marked as "Featured" (Flagthe attribute contains the letter 'a'), then the "Previous" navigation will not be displayed.

    `twig {# If the article's Flag attribute does not contain 'a' (recommendation), then display 'Previous Article' #} {% if 'a' not in archive.Flag %}

    {% prevArchive prev %}
        {% if prev %}
            <a