An efficient content management system, AnQi CMS provides a variety of functions to help operators manage and display website content.Among them, the "Recommended Features" function is a very practical tool that allows us to flexibly mark documents, thereby realizing dynamic filtering and display of specific content in different areas of the website.This article will discuss in detail how to use recommendation attributes in the Aiqi CMS to filter document lists, making the website content more vibrant and attractive.

Part One: Understanding the recommendation attributes of AnQi CMS

In the AnQi CMS backend, when we publish or edit a document, we will see a setting item named "Recommended Properties".These properties are like different tags applied to articles, used to identify their importance, eligibility for display at specific locations, or special display effects.

  • Headline [h]:English version: Typically used in the most prominent position on the website homepage, displaying the most important and most concerned content.
  • Recommend [c]:English version: Refers to high-quality content recommended by editors, which can appear in multiple recommended positions.
  • Slideshow [f]:Commonly used in carousel or large focus image areas, attracting users' attention.
  • [en] Recommended [a]:Specially recommended content, which may have higher weight or an independent display area.
  • [en] Scroll [s]:For continuous display in scenarios such as news rolling and bulletin strips.
  • [en] Image [p]:Indicates that the content is suitable for display primarily in the form of images, such as image news or albums.
  • [en] Jump [j]:Indicates that the document is an external link or an internal jump, and clicking on it will directly jump to the specified URL.

When editing documents in the background, we can select one or more recommended properties based on the importance of the content or the expected display effect.For example, a latest important news can be set as both "headline" and "recommendThis flexible marking method lays a foundation for the dynamic display of front-end content.

Part two: How to use recommended attributes to filter document lists in templates

We need to use the powerful template of Anqi CMS on the front end of the website to filter and display the document list based on these recommended properties,archiveListLabel.archiveListTags allow us to specifyflagFilter documents with specific recommendation properties using parameters.

flagThe parameter accepts a single recommendation property letter identifier. Although multiple recommendation properties can be selected for a document in the background when editing documents, in the front-end template, eacharchiveListcall,flagParameters usually correspond to a recommended attribute for filtering.

The following is a basicarchiveListTag usage example, used to filter out articles set to the 'Top News' attribute:

{# 筛选出最新5篇设置为“头条”属性的文章 #}
<div class="headlines-section">
    <h2>最新头条新闻</h2>
    <ul>
        {% archiveList topNews with moduleId="1" flag="h" limit="5" order="id desc" %}
            {% for item in topNews %}
                <li class="news-item">
                    <a href="{{ item.Link }}" title="{{ item.Title }}">{{ item.Title }}</a>
                    <span class="publish-date">发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </li>
            {% else %}
                <p>当前暂无头条新闻。</p>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Code analysis:

  • {% archiveList topNews with ... %}: This is the core tag for calling the document list.topNewsThe variable name defined for this query result, which you can use in the loop.
  • moduleId="1": Specify the content model ID to be queried. The default article model ID for Anqi CMS is 1, and the product model ID is 2. Fill in according to actual needs.
  • flag="h": This is the key parameter of this topic, it tells the system to only filter out documents marked as 'Top News' attribute (h). The number of displayed documents is limited to 5.
  • limit="5": Limit the number of displayed documents to 5.
  • order="id desc": 按照文档ID降序排列,通常意味着最新发布的文档排在前面。您也可以根据views desc(浏览量降序)或sort desc(后台自定义排序)等进行调整。
  • {% for item in topNews %} ... {% endfor %}TraversaltopNewsThe document list obtained in the variable.
  • item.Linkanditem.Title: Retrieve the link and title of the document.
  • item.CreatedTimeandstampToDate(...):item.CreatedTimeGet the creation timestamp of the document,stampToDateFilter then formats it into a readable date format of “Year-Month-Day”.
  • {% else %} ... {% endfor %}: If no documents matching the criteria are found, the alternate content here will be displayed.

By flexible adjustmentflagThe value of the parameter, combined with other filtering conditions, allows you to build various dynamic and precise document lists.

Part Three: Practical Examples and Code Analysis

The following demonstrates through several practical examples how to filter document lists based on recommended properties to meet different website content display needs.

Example one: Display area of the home page slideshow

Suppose your website home page has a carousel