How to filter and display a list of specific content based on recommendation attributes (such as "Headline

Calendar 👁️ 73

When operating a website, we often need to highlight certain important or recommended content, such as placing the latest news at the "headlines" or marking popular products as "recommended".AnQiCMS provides a flexible recommendation feature that allows you to easily filter and display specific content, thereby better guiding users to browse and enhance content value.

Understand the recommended attributes and their functions

Recommended properties in AnQiCMS, which can be considered as a special tag for content, used to mark its importance and display method on the website. These properties are diverse, such as:

  • Headline [h]: Used for the most important and most concerned content on the website.
  • Recommend [c]: Generally refers to the content that needs to be specially recommended to users.
  • Slide [f]: Often used for content in the carousel or focus area.
  • Special recommendation [a]:has special value or content recommended for long term.
  • Scroll [s]:suitable for display in scrolling areas (such as bulletin boards).
  • Image [p]:indicates that the content contains important images, suitable for image lists display.
  • Jump [j]Click to directly jump to the external link instead of the content detail page.

These properties are not mutually exclusive, you can select multiple recommended properties for a document at the same time.For example, an important article can be set as both 'headlines' and 'images'.By flexibly using these properties, you can make the website content more rich in layers and dynamics.

Set recommended properties in the AnQiCMS backend:

When you create or edit documents in the background, you will find a setting item named "Recommended Properties".Here is an example of an article, go to the 'Content Management' module to enter the interface for 'Publish Document' or edit an existing document.In the middle of the document editing interface, there is usually a 'recommended attributes' selection area.You can check one or more corresponding properties based on the importance of the content.After saving the document, these properties will take effect, waiting to be called in the frontend template.

Call specific recommended content in the template

To display these content with specific recommendation attributes on the website front-end, we need to use the AnQiCMS provided in the template file.archiveListThe tag is powerful, able to filter and output content lists based on various conditions.

The key is to filter content based on recommended attributes.archiveListlabel'sflagParameter. You just need to assign the letter code of the recommended attribute you need toflagthe parameter. For example, if you want to display "Top Stories" content, set it toflag="h"; To display "recommended" content, set it toflag="c".

exceptflagparameters, you can also combine other parameters to more accurately control the display of content:

  • moduleId: Specify the model ID of the content. For example,moduleId="1"typically represents an article model,moduleId="2"Represents a product model. This ensures that you are filtering for specific types of content.
  • categoryId: Specify the category ID of the content. If you want to display recommended content under a specific category, you can use this parameter. For example,categoryId="3"Only recommended content under category ID 3 will be displayed.
  • limit: Controls the number of displayed items. For example,limit="5"Up to 5 items will be displayed at most.
  • order: Define the sorting method of the content. Common options includeid desc(Sorted by publication time in reverse order, i.e., the most recent first),views desc(sorted by view count in reverse, i.e., the most popular).

It should be noted that in a singlearchiveListTagged,You can only use one recommended attribute for filtering at a time. If you need to display the content of multiple recommended attributes, you can use multiple separate onesarchiveListCall the tag.

Template code example and explanation

Demonstrate how to filter and display the content list according to recommended properties in the AnQiCMS template with two specific examples.

Example 1: Display the 5 latest 'Top Stories' articles on the homepage

Assuming your website's homepage has a "Latest Headlines" section, you want to display the latest 5 articles marked as "Headlines."

{# 首页热门头条文章区域 #}
<div class="homepage-headlines">
    <h2>最新头条</h2>
    <ul class="article-list">
        {% archiveList headlines with moduleId="1" flag="h" limit="5" order="id desc" %}
            {% for item in headlines %}
            <li class="article-item">
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p class="description">{{ item.Description|truncatechars:100 }}</p> {# 截取前100个字符作为简介 #}
                <span class="publish-date">发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </li>
            {% empty %}
            <li class="no-content">暂无头条文章可供显示。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Code analysis:

  • {% archiveList headlines with ... %}This is the core tag,headlinesIs the variable name you defined for the content list obtained.
  • moduleId="1"Specify that we want to get the content of the article model (assuming the article model ID is 1).
  • flag="h": Precisely filter out all content marked as "Top" attribute.
  • limit="5": Limit to displaying up to 5 articles.
  • order="id desc": Sort by article ID in descending order, which usually means displaying the latest published articles.
  • {% for item in headlines %}:Traverseheadlineseach article in the variable.
  • {{ item.Link }}Get the article link.
  • {{ item.Title }}Get the article title.
  • {{ item.Description|truncatechars:100 }}: Get the article description and usetruncatecharsa filter to truncate the first 100 characters.
  • {{ stampToDate(item.CreatedTime, "2006-01-02") }}: Format the article's creation timestamp into a string of "Year-Month-Day".
  • {% empty %}: It is a very practical tag, whenarchiveListIt will display when no content meets the conditions.{% empty %}the content in the block to avoid blank pages or errors.

Example two: Display 4 'recommended' products in the sidebar of the product category page

Assuming your product category page sidebar needs to display 4 products marked as "recommended", and these products should belong to the current category, sorted by views in descending order.

`twig {# Product category page sidebar recommended products #}

Related articles

How to display thumbnails, titles, and summaries in the article list?

In website operation, how to display the content list efficiently and beautifully is the key to attracting users and increasing the number of visits.A clear display of a thumbnail, title, and introduction of an article list, not only can it help visitors find the content they are interested in at a glance, but it can also effectively improve the website's performance in search engines.AnQiCMS provides rich features and a flexible template system, allowing us to easily achieve such effects.How is the content of the article managed in the AnQiCMS backend?Display thumbnails, titles, and summaries in the article list

2025-11-09

How to independently configure content display templates for each site under multi-site management?

In the AnQi CMS multi-site management system, configuring a dedicated content display template for each site is the key to achieving brand differentiation, optimizing user experience, and meeting specific content display needs.AnQi CMS, with its flexible architectural design, provides various ways to achieve this goal, whether it is from the perspective of the entire site or refined to a specific content type, it can be highly customized. ### Understanding AnQi CMS Template Mechanism Firstly, we need to understand how AnQi CMS organizes and manages templates.All sites share a core template management area

2025-11-09

How to control the display of different content models (such as articles, products) on the front end?

In AnQi CMS, flexibly controlling the display methods of different content models (such as articles, products, cases, etc.) on the front end of the website is the key to improving user experience and meeting diverse business needs.The system provides a powerful and easy-to-understand mechanism that allows you to finely design and manage the presentation effect of the page according to the content type and specific needs. ### Understanding the Basic Role of Content Models Firstly, we need to understand the core position of the content model in the Anqi CMS. The content model is not only defined by the structure of the content, but also determines what data you can collect for different types of content

2025-11-09

How to customize the display layout of the article detail page in AnQiCMS?

In website operation, the article detail page is not just a carrier of content, but also a key link for brand image, user experience, and SEO effect.A well-designed and logically organized detail page that can effectively increase user reading time, reduce bounce rate, and help search engines better understand and crawl content.For friends using AnQiCMS, deeply customizing the display layout of the article detail page is actually more flexible and convenient than you imagine.AnQiCMS as an efficient content management system, deeply understands the needs of content operators

2025-11-09

What device adaptation modes does AnQiCMS support to optimize content display?

With the popularization of mobile internet, the types of devices used by users to access websites are becoming increasingly diverse, ranging from large-screen PC monitors to compact smartphones. The display effect of website content is directly related to user experience and the effective transmission of information.AnQiCMS is well-versed in this field, providing a variety of device adaptation modes to help users flexibly optimize content display and ensure that the website presents a**status**on any device.The device adaptation strategy of AnQi CMS is mainly divided into three types, each mode has its unique implementation method and applicable scenario

2025-11-09

How to set and optimize the static URL structure of a website to enhance the display effect in search engines?

The importance of website operation and URL structure is self-evident.A clear and meaningful URL not only helps users better understand the page content, but is also a key factor in search engine optimization (SEO).Especially for content management systems, properly setting up the pseudo-static URL structure can significantly improve the display effect and user experience of the website in search engines.AnQiCMS as a content management system that focuses on SEO optimization, provides strong and flexible support in this aspect.It not only built-in a variety of commonly used pseudo-static rules

2025-11-09

How to retrieve and display the SEO title and description of the current document in the template?

In website operation, Search Engine Optimization (SEO) is a key element to enhance website visibility.And the page title (Title) and description (Description) as the first information seen by search engines and users browsing, its importance is self-evident.AnQiCMS (AnQiCMS) knows this and therefore provides a flexible and powerful mechanism to retrieve and display these SEO elements in the template.### AnQi CMS's TDK (Title, Description,

2025-11-09

How to implement the function of displaying and switching content in multiple languages?

Make your website go global: Anqi CMS multilingual content strategy and implementation In today's globalized digital age, many businesses and content creators hope that their websites can reach a wider audience.This means providing content display and switching functions in multiple languages to meet the reading habits of users in different countries and regions.AnQiCMS (AnQiCMS) is an efficient content management system that fully considers this requirement, providing a flexible solution to help you easily implement the multilingual function of the website.In AnQi CMS, implement multi-language display and switching of content

2025-11-09