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

AnQi CMS provides us with great freedom with its efficient architecture based on the Go language and excellent customizability.In the daily content operation, we often hope that the website can intelligently display content, both convenient for users to browse and in line with 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 on product details, special pages, or some special promotional pages, and may even distract the user's attention.

UnderstandingprevArchiveTag

In the AnQi CMS template system,prevArchiveIt is a very practical template tag. It is usually used on article detail pages, and it can automatically capture the previous content of the current document in terms of time or ID sequence, and generate the corresponding link and title, convenient for users to read in continuity.Its basic usage is usually like this:

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

This code will determine if the previous article exists. If it does, it will display its link and title.Otherwise, it may show "nothing" or simply not display anything.Our goal is to add a layer of custom condition judgment on the 'whether to display or not' logic.

Core idea: The power of conditional judgment

The AnQi CMS template engine is similar to Django, providing powerful conditional judgment capabilities, which is the key to our fine-grained control. On each document detail page template, we can directly access a namedarchiveThe global object that contains all the details of the current document, such as the document ID (archive.Id), Title (archive.Title)、the category ID (archive.CategoryId) Content model ID (archive.ModuleId)、and even custom fields, etc.

Utilize{% if ... %}Labels, we can then usearchivethese properties in the object to decide whether to displayprevArchivenavigation.

1.to judge based on the content model (Module ID)

A highlight of Anqi CMS is its flexible content model.We can create different models to manage articles, products, cases, etc.Assuming we have an "article model" (the default ID may be 1) and a "product model" (the assumed ID is 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 to2If it is displayed normally. On the contrary, if it is a product model, the entire content within the block will not be rendered, thereby cleverly hiding the navigation.ifThe content within the block will not be rendered, thereby cleverly hiding the navigation.

2.Judgment based on category (Category ID)

In addition to the content model, document classification is also a commonly used way to distinguish content types.Sometimes, we may only want to hide the 'Previous' navigation for a specific category (such as 'Special Deals', ID may be 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 when you have multiple models but only want to disable navigation in a specific category.

3.Using custom fields or recommended properties (Flag)

AnQi CMS provides highly flexible custom fields and built-in recommendation attributes (such as We can use these properties for more refined control.

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

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

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

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