In the vast realm of AnQi CMS, content operation experts often face a challenge: how to allow users to easily and quickly find the information they need?Especially when the structure of the website content is complex, such as e-commerce products, real estate information, or various categorized articles, a flexible and efficient filtering mechanism becomes particularly important.Today, we will delve deeply into how Anqi CMS can effectively configure document model parameters, and with powerfularchiveFiltersLabel collaboration to create personalized content filtering functions for your website.

Flexible filtering: A 'tool' for content operations.

AnQi CMS is known for its high flexibility and customizability, among which the 'flexible content model' is one of its core strengths.This means you can define the structure of different types of content according to your business needs, not limited to traditional 'articles' or 'products'.This flexibility provides a solid foundation for implementing complex filters.

Imagine that you are running a real estate website, and users may want to filter real estate information according to multiple dimensions such as 'house type' (apartment, villa, shop), 'area' (Beijing, Shanghai, Guangzhou), and 'price range'.It is almost unimaginable without a mature screening mechanism.Security CMS'sarchiveFiltersTags are born to solve this pain point, they can dynamically generate these filtering conditions and seamlessly integrate with the content list.

Core Foundation: Custom fields of the document model.

archiveFiltersThe reason why tags can provide such flexible filtering capabilities lies in their ability to read and utilize the "document model custom fields" defined in the background.These custom fields are the core foundation for personalized content filtering.

Let's take a step-by-step look at how to configure these key parameters in the Anqi CMS backend:

  1. Enter content model management:Log in to the AnQi CMS backend, navigate to the 'Content Management' menu, and select 'Content Model'.Here is a list of all the defined content models on the website, such as "article model", "product model", etc. You can also create new custom models.
  2. Select or create a model and edit the fields:Click the model you want to edit with the filter feature, or create a new model.In the model editing interface, you will see an area named "Content Model Custom Field".This is where we perform 'magic'.
  3. Define custom fields:Click the "Add Field" button to add a new custom field to your filter criteria. Key configuration items include:
    • Parameter name:This is the Chinese name displayed on the back-end, for example, 'House Type', 'Area'.
    • Call field:This is the lowercase field name used to call the template tag, and it is also the field name stored in the database. It must be in English, for examplehouse_type/region. It is recommended to be concise and meaningful.
    • Field type:This is a crucial step, it determines how the field will bearchiveFilterslabeled and processed.
      • For the filter conditions that need to generate a list of options(For example, house type, area), you should selectSingle choiceHello WorldMultiple selectionsorDrop-down selection.
      • For these selection fields, you need to enter in theDefault valuearea,Enter one predefined option value per lineFor example, if there are three options such as 'Apartment', 'Villa', and 'Commercial', enter them line by line in the default value.Anqi CMS will generate the frontend filtering options based on these default values.
      • “Single-line text”、“numeric” and “multi-line text” fields are typically used for entering content or as the basis for precise searches (via URL parametersq) on which they are notarchiveFiltersThe label is directly used to generate the option list.
    • Mandatory?:Choose whether to force content publishers to fill in this field based on your business needs.
    • Default:In addition to defining options for selection fields, other fields can also be set to default values so that they are automatically filled in when content is published.

By following these steps, you have configured the custom fields that can be used to filter the specific content model.When you publish documents under this model, these custom fields will appear in the 'Other Parameters' collapse box, allowing you to finely label each document.

The magic of front-end templates:archiveFiltersThe application of tags

After the background configuration is completed, the next step is to display these filtering conditions to the user.archiveFiltersTags play a key role in the front-end template.

archiveFiltersTags are usually used on document list pages or category pages, and they combine the context of the current page (such as the current document model ID) to generate the corresponding filter. The basic usage is as follows:

{# 假设我们正在一个文档列表页,需要为模型ID为1的文档生成筛选器 #}
<div>
    <h3>筛选条件:</h3>
    {% archiveFilters filters with moduleId="1" allText="全部" %}
        {% for item in filters %}
        <div class="filter-group">
            <span class="filter-name">{{ item.Name }}:</span>
            <ul class="filter-options">
                {% for val in item.Items %}
                <li class="filter-option {% if val.IsCurrent %}active{% endif %}">
                    <a href="{{ val.Link }}">{{ val.Label }}</a>
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endfor %}
    {% endarchiveFilters %}
</div>

{# 筛选结果通常会与 archiveList 标签结合使用,以显示过滤后的文档列表和分页 #}
<div>
    <h3>筛选结果:</h3>
    {% archiveList archives with moduleId="1" type="page" limit="10" %}
        {% for item in archives %}
        <div class="archive-item">
            <h4><a href="{{ item.Link }}">{{ item.Title }}</a></h4>
            <p>{{ item.Description }}</p>
            {# 这里可以展示其他文档信息,例如自定义字段的值 #}
        </div>
        {% empty %}
        <p>没有找到符合条件的文档。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 分页导航 #}
    {% pagination pages with show="5" %}
        {# 渲染分页链接 #}
    {% endpagination %}
</div>

In this template code:

  • moduleId="1": Specifies which document model (e.g., article model, ID usually 1) to generate a filter for. Ensure that the ID here matches the model ID of the custom field you configured in the backend.
  • allText="全部": Generate a 'All' option for each filtering dimension to facilitate users in canceling a specific filtering condition.
  • filtersThis isarchiveFiltersA label that outputs an array containing all the filterable dimensions (such as "house type", "location").
  • item.NameDisplay the name of the filter dimension (i.e., the 'parameter name' set in the background).
  • item.ItemsAre all the available options under the current filter dimension (i.e., the options you enter on each line in the "default value" section of the backend).
  • val.LinkThis is the URL that will be redirected to when you click on this option, Anqi CMS will automatically handle the URL parameters and filter the content.
  • val.IsCurrentA boolean value indicating whether the current option is selected, convenient for adding on the front endactiveStyle to highlight.

In this way, when the user clicks on a filter option, the page will refresh and display the filtered content list.

Practical suggestions and precautions

  1. Planning comes first:Before you start configuring, first clarify the dimensions of the filters your website needs, and the available options for each dimension. This will help you design the document model more efficiently.
  2. Appropriate field type:Must select the field type "Single choice", "Multiple choice", or "Dropdown" for the filter, and correctly configure the "Default value" as a filter option.
  3. moduleIdIt is crucial:EnsurearchiveFiltersin the labelmoduleIdThe parameter strictly matches the document model ID you want to filter.
  4. Combined with pagination and search: archiveFiltersTags are usually witharchiveList(Used for content list) andpagination(Used for pagination) Tags are used together to provide a complete filtering, display, and navigation experience. Moreover, if you also want to implement keyword search,archiveListTags also supportqParameter.
  5. Front-end style:Although the core function is provided by Anqi CMS, the aesthetics and user experience of the filter largely depend on the front-end CSS and JavaScript code.

Through detailed backend configuration and flexible template application, Anqi CMS'sarchiveFiltersTags can enable your website to have powerful content filtering capabilities, greatly improving the efficiency of users searching for information and the overall user experience of the website.


Frequently Asked Questions (FAQ)

1. What are the naming conventions and注意事项 for the 'call field' of custom fields?“The field name” is the unique identifier you use to reference this custom field data in the template, and it is also the field name in the database.The 'field called' in AnQi CMS must be used in English letters, and it is recommended to use all lowercase letters, avoiding special characters, spaces, or numbers at the beginning.For example, if you define 'House Type', an appropriate field name could behouse_type. Clear and standardized naming helps you quickly understand and reference during template development.

2.archiveFiltersCan the tag be used on any page template of the website?No.archiveFiltersThe label is designed for document list pages or document category pages, it depends on the page context to obtain the current document model information and filtering parameters. It needs to be combined witharchiveListThe use of tags is usually not used independently on the homepage or on a single-page template.If you try to use it on an unsupported page, it may cause the tags to be incorrectly parsed or the filters not to work.

3. If my custom field type is 'Single line text' or 'Multi-line text',archiveFiltersCan the label be used to generate filter options?It cannot generate the option list directly.archiveFiltersLabels are mainly generated for fields that have predefined options (such as "Single choice", "Multiple choice", and "Dropdown") and create clickable filter options. For fields of the type "Single line text" or "Multi-line text", they are usually not used to generate filters.