How to filter and display content on the article list page based on specific conditions (such as recommended attributes)?

Calendar 👁️ 58

In our website content operation, the article list page often plays an important display role.We do not want to simply arrange the content in a mechanical manner based on the publication time, but hope to be able to filter and display articles flexibly according to certain conditions, such as the importance of the content, popularity, or whether they are recommended.AnQiCMS (AnQiCMS) took these needs into consideration from the beginning of its design, providing us with a simple yet powerful content filtering mechanism.

Today, let's talk about how to filter and display content on the article list page of Anqi CMS based on specific conditions (such as "recommended attributes").

Step 1: Set the 'recommended attributes' for the article in the background

To allow the front-end list to filter articles based on the recommended attributes, we first need to tag these 'labels' for the articles in the background.

When you enter the AnQi CMS backend management interface, under the "Content Management" menu, select "Publish Document" or "Edit Document", you will see an option area named "Recommended Properties".This provides a variety of preset properties, such as 'headline[h]', 'recommend[c]', 'slide[f]', and so on.

These properties are like the 'identity markers' of an article.You can check one or more properties for the importance or display intent of the article.For example, an especially important article, you may check both 'Top News [h]' and 'Recommended [c]' at the same time.Of course, if an article does not require any special marking, it is also okay to leave it unchecked.

It is noteworthy that each attribute corresponds to a letter identifier (such as “recommended” corresponds toc,“top news” corresponds toh),this letter will be used for filtering in the front-end template.

The second step: flexibly call and filter content in the template

After setting up the background properties, the next step is to implement the filtering display in the website front-end template.The Anqi CMS uses a syntax similar to the Django template engine, which is very intuitive to use.archiveListThis powerful template tag.

archiveListTags are the core tools used to retrieve lists of articles.It supports various parameters, allowing us to retrieve content based on different conditions.flagParameter.

Assuming we want to display all articles marked as 'recommended[c]' in a specific area, such as the 'Editor's Recommendations' column on the homepage, we can write the template code like this:

{# 假设这里是你的“编辑推荐”模块 #}
<div class="editor-recommend-section">
    <h3>编辑推荐</h3>
    <ul>
        {# 使用 archiveList 标签来获取文章列表 #}
        {% archiveList recommendedArticles with moduleId="1" flag="c" order="id desc" limit="5" type="list" %}
            {% for item in recommendedArticles %}
            <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:80 }}</p>
                    <span class="publish-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </a>
            </li>
            {% empty %}
            <li>
                抱歉,目前没有推荐文章。
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Let us simply decode this code:

  • archiveList recommendedArticles with ...: This is calling the article list tag and storing the obtained data inrecommendedArticlesthis variable.
  • moduleId="1": This parameter specifies the content of the 'article model'. If the recommendation attribute is set for the product, then this might bemoduleId="2"(or any custom model ID).
  • flag="c"This is the key to filtering based on the 'recommended [c]' attribute! It tells the system to only return articles marked as 'recommended'.
  • order="id desc": We can choose the sorting method for the articles, here it is in descending order by ID, which means the latest recommended articles will be at the top. You can also change it toorder="views desc"Show the most viewed recommended articles.
  • limit="5": We limit to show the latest 5 recommended articles.
  • type="list": It means we are just getting a simple list without pagination functionality. If pagination is needed, it can be set totype="page"and combiningpaginationlabel usage
  • {% for item in recommendedArticles %}: This is a loop, traversingrecommendedArticlesof each article's data.
  • {{ item.Link }},{{ item.Title }},{{ item.Thumb }},{{ item.Description }},{{ item.CreatedTime }}These are the built-in fields of the article, accessed byitem.the prefix directly.item.Description|truncatechars:80Used a filter to truncate the description length.stampToDateIs an AnQi CMS provided date formatting function, making time display more friendly.
  • {% empty %}: This is a very practical feature, whenrecommendedArticlesis empty (that is, there are no articles that meet the conditions), it will displayemptyBlock content.

More filtering combinations

In addition to simply filtering "recommended" articles, you can also flexibly combine other parameters:

  • Exclude specific attributes:If you want to display all articles except 'Top Stories', you can useexcludeFlag="h".
  • Filter recommended articles under specific categories:CombinecategoryIdparameters, for examplecategoryId="10" flag="c"which means only display recommended articles with category ID 10.
  • Display the recommended attribute itself:If you want to display the recommended attribute of the article in the list item (for example,archiveListaddshowFlag=trueparameter, and then use it in the loop.{{item.Flag}}to retrieve and display it.

Application based on actual scenarios

This filtering capability based on recommendation attributes is very useful in actual operation:

  1. Homepage of the website:Can set 'Today's Headlines', 'Editor's Choice', 'Slide Recommendations', and other modules, which are displayed through differentflagto show the corresponding content.
  2. Sidebar / Bottom Recommendations:“Popular Articles”, “Latest Recommendations”, and other areas can be utilizedflagandorderParameters such as sorting by views can easily achieve dynamic content display.
  3. Special topic page:When creating a special topic, you can mark specific articles within the topic with exclusive recommendation attributes, and then accurately call up these selected contents on the topic page.

Provided by Anqi CMSarchiveListThe tag and recommendation attribute feature allows us to easily build a rich, well-structured article list page, making website content operations more efficient and flexible.


Frequently Asked Questions (FAQ)

1. Can I filter articles with multiple recommended attributes in the same tag, such as both "Headline[h]" and "Recommended[c]"?archiveList标签中同时筛选多个推荐属性的文章,比如既要“头条[h]”又要“推荐[c]”?Of Security CMSarchiveListThe tag is inflagThe parameter is currently designed to support filtering only one recommended attribute per call. If you need to display articles that have both the "Top" and "Recommended" attributes, or need to display articles that contain "Top"orArticles with the "Recommended" attribute, you need to call separatelyarchiveListLabel, or set a completely new combination attribute for these articles in the background (if the business logic allows), but the more common and recommended practice is to use a singleflagThe parameter is used to retrieve a list of recommended content of a specific type.

2. How to directly display the recommended attribute next to the article title, such as '[Recommended] Anqi CMS Beginner's Guide'?This is achievable. InarchiveListAdd a tag, inshowFlag=trueThe parameter. So, when looping through article data, eachitemobject will contain aFlagfield, whose value is the recommended attribute letter of the article (for examplec). You can display it in the template like this:

{% archiveList articles with moduleId="1" limit="5" showFlag=true %}
    {% for item in articles %}
    <li>
        {% if item.Flag %}[{{ item.Flag }}]{% endif %}
        <a href="{{ item.Link }}">{{ item.Title }}</a>
    </li>
    {% endfor %}
{% endarchiveList %}

You can even base it onitem.Flagto make conditional judgments based on the value, displaying friendlier text, such ascdisplaying as "Recommended", andhdisplaying as "Headline".

3. Is this filter function also applicable to product lists or other custom content models?Absolutely. Anqi CMS'archiveListThe tag is a generic content list tag, it passes throughmoduleIdSpecify the content model to operate. Whether it is an article, product, or any content type you customize through the "Content Model" feature, as long as you set the "recommended attributes" for these contents in the background, you can display them in the foreground bymoduleIdcooperateflagParameters are filtered and displayed. For example, to filter "Product Model" (

Related articles

How to format a timestamp into a readable format

## Let Time Speak: How to Format Timestamps into Readable Dates in Anqi CMS When operating a website, the timeliness of content is often a point of great concern for users.Whether it is the publication time of the article, the update time of product information, or the specific moment of user comments, clear and intuitive dates and times can greatly improve the user experience, and even have a positive impact on search engine optimization (SEO).However, in the backend of the content management system, we sometimes see time presented as a long string of numbers, like `1609470335`.

2025-11-08

How to safely output user-generated content in AnQiCMS templates to prevent XSS attacks from affecting the display of the page?

The website content operation is in progress, user-generated content (UGC) is undoubtedly a valuable resource for enhancing the vitality and interactivity of the website.Whether it is comments, messages, forum posts, or articles edited with a rich text editor, all of these greatly enrich the information ecology of the website.However, potential security risks come with UGC, the most common and severe of which is cross-site scripting (XSS) attacks.If not prevented, malicious script code may be executed in the user's browser, stealing user data, and tampering with the page

2025-11-08

How to implement the template inheritance function of AnQiCMS, so that the content block display of master page and sub page can be overlaid and customized?

How template inheritance in AnQiCMS allows the parent page and child page to perform their respective functions?In website content management, maintaining consistent page style while being able to flexibly modify local content is a goal pursued by many operators.AnQiCMS uses a syntax similar to the Django template engine, providing us with an elegant solution, that is, the powerful template inheritance feature.With this feature, we can cleverly design master pages and subpages, making the website structure both unified and highly customizable.

2025-11-08

How to use the `macro` macro function in AnQiCMS templates to define reusable content display segments to improve efficiency?

In AnQi CMS, efficiently managing website content and front-end display is the key to daily operations.When faced with some repetitive page elements, such as article list items, product cards, or buttons with specific styles, if you rewrite the code every time, it not only takes time and effort, but is also prone to errors, and future modifications and maintenance will become extremely complex.

2025-11-08

What ways does Anqi CMS support to adjust the overall content display mode of the website (adaptive, code adaptation, PC+mobile independent site)?

AnQi CMS: Three Flexible Options for Customizing Website Content Display Mode How to present the effect of website content on different devices is an important issue that every webmaster needs to consider when building and operating a website.Anqi CMS understands this point and therefore provides a variety of flexible content display modes, allowing you to choose the most suitable way to build your website according to your actual needs.No matter if you are pursuing a simple and efficient experience or need an ultimate customization experience, AnQi CMS can provide strong support.Next, we will delve into the three website content display modes supported by Anqi CMS

2025-11-08

How to utilize the flexible content model of Anqi CMS to define display fields for different types of content?

Today, with the increasing richness and diversity of digital content, the flexibility of a website content management system (CMS) is crucial.AnQiCMS (AnQiCMS) is well aware of this, one of its core advantages is that it provides a powerful "flexible content model" feature, allowing users to customize exclusive display fields for various content according to different business needs.This greatly enhances the adaptability of the website, making content operation more efficient and personalized.

2025-11-08

How does AnQi CMS ensure the correct switching and display of different language content on a multilingual website?

Today, with the deepening of globalization, website content can reach different language user groups and has become a key factor for enterprises to expand the market and enhance brand influence.For users who operate multilingual websites, one of the most concerning issues is how to ensure the correct switching and display of different language content?AnQiCMS (AnQiCMS) provides a clear and efficient solution in this regard, let's take a look at how it is implemented.

2025-11-08

How to optimize the URL structure through pseudo-static rules to improve the display effect of content in search engines?

When operating a website, we all hope that our content can be seen by more users, and search engines are undoubtedly an important source of traffic.To perform well in search engines, in addition to the quality of the content itself, the structure of the website's URL (website address) also plays a crucial role.A clear and friendly URL, not only makes it easier for users to understand and remember, but also helps search engines better crawl and understand our content.And the static rules, which are an effective means to optimize URL structure, AnQiCMS (AnQiCMS) provides very convenient functions in this aspect.###

2025-11-08