AnQi CMS is an efficient content management system that provides a variety of features to help operators manage and display website content.Among the "Recommended Properties" feature, it is a very practical tool that allows us to mark documents flexibly, thus enabling dynamic filtering and displaying specific content in different areas of the website.This article will discuss in detail how to use recommendation attributes in Anqi CMS to filter document lists, making the website content more vibrant and attractive.
Part 1: Understanding the recommended attributes of AnQi CMS
In the AnQi CMS backend, when we publish or edit a document, we will see a setting item named "Recommendation Properties".These properties are like different tags attached to an article to indicate its importance, eligibility for display at specific locations, or special display effects.The system is built-in with a variety of recommended attributes, each attribute corresponds to a short letter identifier, convenient for calling in templates:
- Headline [h]: Typically used in the most prominent position on the website homepage, displaying the most important and most concerned content.
- Recommend [c]: Refers to high-quality content recommended by editors, which can appear in multiple recommended positions.
- Slide [f]: Often used in carousel or large focus image areas, attracting the attention of users.
- Special recommendation [a]: Especially recommended content, which may have higher weight or an independent display area.
- Scroll [s]: Suitable for continuous display in news scrolls, bulletin boards, and other scenarios that require continuous display.
- Image [p]: Indicates that the content is suitable for display mainly in the form of images, such as image news or albums.
- Jump [j]This indicates that the document is an external link or an in-site jump, 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 recent important news can be set as both 'headline' and 'recommendation', while a beautifully crafted product album can be set as 'slideshow' and 'image'.This 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 the template.
We need to use the powerful Anqicms template to filter and display the document list according to these recommended properties on the front end of the websitearchiveList.archiveListTags allow us to specifyflagParameters to filter documents with specific recommendation properties.
flagThe parameter accepts a single recommended attribute letter identifier. Although multiple recommended attributes can be selected for a document in the background editing of the document, in the front-end template, eacharchiveListcall,flagParameters usually correspond to a recommended attribute for filtering.
Here is a basicarchiveListexample of tag usage, used to filter out articles set to the "headline" 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.topNewsThis is the variable name defined for this query result, which you can use in the loop.moduleId="1": Specify the content model ID to be queried. AnQi CMS defaults to article model ID 1, product model ID 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) of the document.limit="5": Limit the number of displayed documents to 5.order="id desc": Sort by document ID in descending order, which usually means the latest released documents are at the top. You can also adjust according toviews desc(view count in descending order) orsort desc(custom sorting on the backend) and so on.{% for item in topNews %} ... {% endfor %}: TraversetopNewsThe document list obtained in the variable.item.Linkanditem.Title: Retrieve the link and title of the document separately.item.CreatedTimeandstampToDate(...):item.CreatedTimeGet the creation timestamp of the document,stampToDateThe filter formats it into a readable date format of 'Year-Month-Day'.{% else %} ... {% endfor %}If no documents matching the criteria are found, the alternative content here will be displayed.
By flexible adjustmentflagThe value of the parameter, combined with other filtering conditions, allows you to build various dynamic and accurate document lists.
Part three: practical examples and code analysis
Below are several practical examples that further demonstrate how to filter document lists based on recommended attributes to meet the different content display needs of various websites.
Example one: Display area of the homepage slider
Assuming your website homepage has a carousel