How to filter and display a document list based on specific recommendation attributes (such as 'Headline', 'Recommendation')?

Calendar 👁️ 66

In AnQiCMS, the flexible application of content recommendation properties is a key link to enhance the exposure and user experience of website content.Whether you want to highlight important news on the homepage or recommend selected content in specific sections, AnQiCMS provides convenient and efficient solutions.This article will delve into how to filter and display document lists based on specific attributes such as "Headlines", "Recommendations", and others, helping you better manage and present website content.

Part One: Understanding Recommendation Attributes and Their Settings

In the AnQiCMS content management system, the recommended attribute is a very practical feature that allows us to mark documents with different importance levels or display methods.These properties typically include but are not limited to 'headline', 'recommendation', 'slideshow', etc., each corresponding to a short letter identifier for easy use in templates.

In particular, AnQiCMS provides the following commonly used recommendation properties:

  • Headline [h]: Usually used for the most important and most highlighted content on the website.
  • Recommend [c]: Indicates that the content is recommended for editing, suitable for display in lists or sidebars.
  • Slide [f]: Content designed specifically for carousels or focus images.
  • Special recommendation [a]: A special recommendation, which may have a higher priority.
  • Scroll [s]: Suitable for displaying content in a scrolling manner on a page, such as a bulletin board.
  • Bold [h]Text-level emphasis, but may also be used for content filtering in some template designs.
  • Image [p]Emphasized content includes important images, may be used in image lists.
  • Jump [j]: Indicates that clicking on this content will jump to an external link or specified page.

How to set recommended attributes in the background?

When you publish or edit a document, you will see a section called "Recommended Properties" prominently displayed in the document editing interface.Here, you can check one or more recommended properties based on the actual needs of the document.For example, if an article is a major content on the current website, you can check 'Headline[h]' and 'Recommend[c]'.AnQiCMS allows you to select, multi-select, or not select these properties, which lays the foundation for flexible display of front-end content.

It should be noted that although the background can select multiple recommended properties for the document, when calling the front-end template tags, it will usually filter for a single property.

Part two: usearchiveListTags for filtering and display

AnQiCMS template system adopts a syntax similar to Django, wherearchiveListTags are the core tools for obtaining document lists. By using them flexibly,archiveListThe label's parameters, we can easily implement the need to filter documents by recommended attributes.

Basic filtering: Get documents with specific recommended attributes.

To filter documents with specific recommendation properties, we mainly usearchiveListlabel'sflagParameter.flagThe value of the parameter is the letter identifier we see when setting recommendation properties in the background.

Suppose we want to get the latest 5 articles with the 'headline' attribute and display them as a list, we can write the template code like this:

{# 获取带有“头条”属性 (flag="h") 的最新5篇文档 #}
<div class="headlines-section">
    <h3>头条新闻</h3>
    <ul>
        {% archiveList archives with flag="h" limit="5" order="id desc" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        <h4>{{ item.Title }}</h4>
                        <p>{{ item.Description|truncatechars:80 }}</p>
                        <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                        <span>浏览量:{{ item.Views }}</span>
                    </a>
                </li>
            {% empty %}
                <li>暂无头条新闻。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In this example:

  • flag="h"Specify only the documents that have the 'Top News' attribute.
  • limit="5":Limit to displaying only 5 articles.
  • order="id desc"Arrange the documents in descending order by document ID, usually representing the most recently published documents.
  • item.Link/item.Title/item.Description/item.CreatedTime/item.ViewsIt is a commonly used field in the document object, you can choose to display it as needed.stampToDateIt is a practical time formatting function.
  • truncatechars:80It is a filter used to truncate the description content to prevent it from being too long.

Advanced filtering and pagination: combining other parameters and pagination features

We can not only filter according to recommended attributes, but also combine classification, content models, and other fine-grained filtering, and implement pagination display.

Suppose we want to display all 'recommended' documents under a specific category (for example, the article category with ID 10) and support pagination, with 10 documents displayed per page:

{# 获取分类ID为10下,带有“推荐”属性 (flag="c") 的文档,并分页显示 #}
<div class="recommended-articles">
    <h3>推荐文章列表</h3>
    <ul>
        {% archiveList archives with categoryId="10" flag="c" type="page" limit="10" order="id desc" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {% if item.Thumb %}<img src="{{ item.Thumb }}" alt="{{ item.Title }}">{% endif %}
                        <h4>{{ item.Title }}</h4>
                        <p>{{ item.Description|truncatechars:100 }}</p>
                        <span>{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    </a>
                </li>
            {% empty %}
                <li>当前分类下暂无推荐文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>

    {# 分页导航 #}
    <div class="pagination-section">
        {% pagination pages with show="5" %}
            {# 可以根据pages变量的属性,如pages.FirstPage.Link, pages.Pages等,构建完整的分页导航 #}
            {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
            {% for page in pages.Pages %}<a class="{% if page.IsCurrent %}active{% endif %}" href="{{ page.Link }}">{{ page.Name }}</a>{% endfor %}
            {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
        {% endpagination %}
    </div>
</div>

In this example:

  • categoryId="10": The document must belong to the category with ID 10.
  • flag="c": Specify the "recommended" attribute filter.
  • type="page": Enable pagination function, so thatarchiveListThe tag will return the data needed for pagination, rather than returning all results at once.
  • limit="10": Displays 10 documents per page.
  • {% pagination pages with show="5" %}: Combined with the pagination tag, it will automatically according toarchiveListThe label returns the pagination data to generate pagination links.

Exclusion of documents with specific attributes

In addition to filtering specific attributes, sometimes we may need to exclude documents with certain attributes.For example, in a regular article list, we may not want to display documents that have been marked as "headline" to avoid repetitive content display or to分散 focus.This can be used at this timeexcludeFlagParameter.

{# 获取所有文章,但排除掉“头条” (excludeFlag="h") 文档 #}
<div class="all-articles">
    <h3>最新文章 (排除头条)</h3>
    <ul>
        {% archiveList archives with moduleId="1" type="list" limit="10" order="id desc" excludeFlag="h" %}
            {% for item in archives %}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
            {% empty %}
                <li>暂无文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

HereexcludeFlag="h"Will ensure that the list of articles obtained does not contain any documents marked with the "headline" attribute.

Display recommended property identifier in document list

If you want to display the recommended properties of the document directly in the document list, you canarchiveListthe tag withshowFlag=trueParameter.

"`twig {# Get the article and display its recommended attribute identifier #} <div class=“articles-

Related articles

How to call and display the data of the custom model field in the document?

In Anqi CMS, the flexible content model is one of its core strengths, allowing us to create various information carriers such as articles, products, and more according to different business needs and define unique properties for them.How to present the data of these customized fields in the website front-end after we have set them for the document is a major concern for many users.This article will provide a detailed explanation of this process, helping you easily master the custom model fields of Anqi CMS. ### Understanding the Value of Custom Model Fields Firstly, let's clarify the importance of custom model fields.

2025-11-08

How to display the titles and links of the previous and next documents on the document detail page?

In website content operation, it is crucial to provide readers with a smooth reading experience.If a user finishes reading a document and can easily navigate to the previous or next related content, it not only effectively extends the user's stay on the website and increases page views, but also helps search engines better understand the structure and content relevance of the website, thereby having a positive impact on SEO.AnQiCMS (AnQiCMS) has fully considered this point in the design of template functions, providing simple and powerful tags, making it easy to display the title and link of the previous and next documents on the document detail page

2025-11-08

How to display a list of recommended documents related to the current document on the document detail page?

In website content operations, providing users with relevant recommended content not only effectively enhances the depth and duration of page browsing, but also optimizes user experience, indirectly assisting in the SEO performance.In AnQiCMS (AnQi Content Management System), implementing this feature is flexible and direct.Next, we will discuss how to seamlessly integrate and display the recommended document list closely related to the current document on the document detail page. ### Core Value: Why should recommended documents be displayed on the document detail page?

2025-11-08

How to get and display the name and link of the category to which the current document belongs?

On the content detail page of a website, we often hope to clearly display the classification information of the current document, such as the name of the classification and the link to that classification.This not only helps visitors better understand the content structure, but also improves the website's navigation and user experience.Safe CMS provides us with a variety of flexible ways to meet this requirement. We will discuss several methods for obtaining and displaying the category name and link of the current document in the AnQiCMS template, and you can choose the most suitable solution according to your actual template design and requirements.### Method One

2025-11-08

How to implement keyword search and display results on the document list page?

How to help visitors quickly and accurately find the information they need in the face of increasingly large amounts of website content is the key to improving user experience and website value.AnQiCMS (AnQiCMS) is deeply proficient in content management, providing us with a powerful and flexible keyword search mechanism that allows the document list page to easily implement keyword search and elegantly present the results.

2025-11-08

How to implement multi-condition (such as custom parameters) filtering function on the document list page?

In AnQi CMS, implementing multi-condition filtering functionality on the document list page, especially filtering based on custom parameters, is crucial for improving user experience and helping users quickly find the content they need.AnQi CMS with its flexible content model and powerful template tag system makes this feature highly efficient and intuitive.The entire process can be divided into several core steps: First, define your content model and custom filter fields in the background;Secondly, build the display interface for the filtering conditions in the template; finally, present the filtering results in the document list using list tags.--- ### One

2025-11-08

How to set pagination for a document list and display page navigation?

In modern website operations, setting up pagination for content lists is almost indispensable.It can not only significantly improve the user's browsing experience, avoid the slow loading caused by the long content of a single page, but also help search engines better crawl and index the website content.For friends using AnQi CMS, implementing pagination for the document list and displaying page navigation is a very intuitive and powerful feature.Our AnQi CMS provides flexible template tags, allowing full control over content display.To set pagination for the document list and display page navigation in a friendly manner

2025-11-08

How to display the name of a specified category

Flexible display of category names in AnQiCMS: A comprehensive template call guide Content categories are the core of the website structure, not only helping to organize and manage massive information, but also guiding users to browse the website and improve the user experience.Whether it is an article list, product details, or side navigation, clearly displaying category names can make the content of your website more organized.

2025-11-08