English CMS provides operators with a rich set of tools to organize and display website content with its flexible and efficient content management capabilities.The "Recommended Attributes" (Flag) is a very practical feature that allows you to easily classify and mark articles, thus enabling precise content filtering and dynamic display on the website front end.This article will introduce in detail how to use these recommended properties in AnQiCMS to filter and display the specific article list you want.
Deep understanding of AnQiCMS recommendation attributes (Flag)
AnQiCMS's recommended attribute, as the name implies, is a special tag applied to articles, used to indicate some characteristics or importance of the article.These properties can be flexibly set when you edit articles, and they are like 'tags' or 'status' of the article, helping you to achieve fine-grained content presentation in the front-end template.
In the 'Add Document' interface of AnQiCMS backend, you will see the item 'Recommended Attributes'. It provides a series of preset attributes and their corresponding single-letter identifiers:
- Headline [h]: 通常用于网站首页最重要、最受关注的文章。
- Recommend [c]: 指示该文章是编辑推荐的优质内容。
- Slideshow [f]: 适用于在幻灯片或轮播图中展示的文章。
- [en] Recommended [a]: Articles with special recommendation value.
- [en] Scroll [s]: Content suitable for display in scrolling news or announcement areas.
- 加粗 [English]: (Note: This identifier is the same as the 'Headline' attribute, may be used for visual emphasis, depending on the template implementation)
- [en] Image [p]: 表明该文章拥有高质量的图片,适合图片展示区域。
- [en] Jump [j]: 通常用于文章点击后会跳转到外部链接的情况。
You can select one or more recommended attributes for each article, or you can choose none. These flexible tags are the core basis for content filtering in our front-end template.
Apply recommended attribute filtering to article list in the template
To filter and display the article list in the AnQiCMS front-end template based on recommended attributes, we will mainly usearchiveListThis powerful template tag.
archiveListTags provideflagandexcludeFlagTwo parameters, specifically used for handling the filtering needs of recommendation attributes.
1. Filter articles with specific recommendation attributes
If you want to display articles with a specific recommendation attribute only, such as displaying articles with the 'recommended' attribute ([c]), you can use it like thisarchiveListTags:
{% archiveList recommendedArticles with flag="c" limit="10" %}
{% for item in recommendedArticles %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
<p>{{item.Description}}</p>
</a>
</li>
{% empty %}
<li>当前没有推荐文章。</li>
{% endfor %}
{% endarchiveList %}
In this code block:
archiveList recommendedArticlesWe defined a variablerecommendedArticlesTo store the filtered list of articles.flag="c": This is the key. It tells AnQiCMS to only retrieve articles marked as 'Recommended'.limit="10":Limit to displaying the latest 10 articles. You can adjust this number as needed.
It should be noted that, according to the documentation of AnQiCMS,flagParameters can only specify one recommended property character at a time (such as"c"/"f"), used to selectively display articles.
2. Exclude articles with specific recommended properties
Sometimes you may want to display all articles under a certain category, but exclude those with specific recommendation attributes, such as excluding articles with the 'slide' attribute ([f]). In this case, excludeFlagThe parameter comes into play.
{% archiveList regularArticles with categoryId="1" excludeFlag="f" limit="5" %}
{% for item in regularArticles %}
<li>
<a href="{{item.Link}}">
<h4>{{item.Title}}</h4>
</a>
</li>
{% empty %}
<li>当前没有符合条件的文章。</li>
{% endfor %}
{% endarchiveList %}
In this example:
categoryId="1":Specify articles to filter under category ID 1 only.excludeFlag="f":Exclude all articles marked with the 'Slide' attribute, even if they belong to the specified category.- With
flagParameters are different,excludeFlagParameters can accept multiple recommended attribute characters, separated by commas, for exampleexcludeFlag="f,s"Indicates that the articles should exclude both 'Slide' and 'Scroll' attributes.
3. Combine other parameters to achieve more precise filtering
flagandexcludeFlagParameters can be witharchiveListFlexible combination of other label parameters to meet more complex filtering needs, such as:
- Filter by model (
moduleId):If you want to filter 'recommended' products in the product model, you can addmoduleId="2"(Assuming the product model ID is 2)。 - Filter by category (
categoryId):As shown in the above example, it is possible to limit attribute filtering to a specific category. - Sort by (
order):can be combined withorder="views desc"Display articles with specific attributes and the highest page views. - Page display (
type="page"): If the number of filtered articles is large, you can use the pagination feature to display.
For example, display the latest 5 "Top News" articles in the article model (ID 1) with category ID 5:
{% archiveList headlineNews with moduleId="1" categoryId="5" flag="h" order="id desc" limit="5" %}
{% for item in headlineNews %}
<div class="headline-item">
<img src="{{item.Thumb}}" alt="{{item.Title}}">
<h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
<span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
</div>
{% endfor %}
{% endarchiveList %}
Practical Case: Customize your content display
Imagine your website's homepage has a 'Featured Recommendations' section, which needs to display several articles that are specially recommended by the editor; at the same time, in the sidebar of the article list page, you want to show some popular articles, but do not want the slide articles on the homepage to repeat.
Case one: Home page featured recommendation area
`twig
<h2>精选推荐</h2>
<div class="articles-grid">
{% archiveList featured with moduleId="1" flag="c" limit="4" %}
{% for item in featured %}
<article class="recommend-card">
<a href="{{item.Link}}">
{% if item.Logo %}<img src="{{item.Logo}}" alt="{{item.Title}}">{% endif %}