An QiCMS provides operators with a rich set of tools to organize and display website content with its flexible and efficient content management capabilities.Among them, the "recommended attribute" (Flag) is a very practical feature that allows you to easily classify and mark articles, and then implement precise content filtering and dynamic display on the website front-end.This article will introduce in detail how to use these recommended attributes in AnQiCMS to filter and display the specific article list you want.
Comprehend AnQiCMS recommendation attributes (Flag)
AnQiCMS's recommended attribute, as the name implies, is a special mark applied to articles to indicate some characteristics or importance of the article.These properties can be flexibly set when you edit the article, they are like the "tags" or "status" of the article, helping you to achieve fine-grained content presentation in the frontend template.
In the AnQiCMS backend "Add Document" interface, you will see the item "Recommended Properties". It provides a series of preset properties and their corresponding single-letter identifiers:
- Headline [h]: Usually used for the most important and most concerned articles on the website homepage.
- Recommend [c]: Indicates that the article is a high-quality recommended content by the editor.
- Slide [f]: Suitable for displaying articles in slideshows or carousels.
- Special recommendation [a]: Articles with special recommendation value.
- Scroll [s]: Content suitable for display in scrolling news or announcement areas.
- Bold [h]: (Note: This identifier is the same as the "Headline" attribute and may be used for visual emphasis, depending on the template implementation)
- Image [p]: Indicates that the article has high-quality images suitable for display in the image area.
- Jump [j]: Usually used when clicking on the article will jump to an external link.
You can select one or more recommended attributes for each article, or you can choose not to. These flexible tags are the core basis for content filtering in our front-end templates.
Apply recommended attributes to filter the article list in the template
We will mainly use recommended attributes to filter and display the article list in the AnQiCMS front-end template.archiveListThis powerful template tag.
archiveListTags providedflagandexcludeFlagTwo parameters, specifically used for handling recommendation attribute filtering requirements.
1. Filter articles with specific recommendation attributes.
If you want to display articles with a specific recommendation attribute, such as only 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 have defined a variablerecommendedArticlesto store the list of filtered articles.flag="c"This is the key. It tells AnQiCMS to only retrieve articles marked as 'recommended'.limit="10": Limit to display the latest 10 articles. You can adjust this number as needed.
It should be noted that according to the documentation of AnQiCMS,flagA parameter can only specify one recommended 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 [f] attribute. At this point,excludeFlagThe parameters come 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 to filter articles only in category ID 1.excludeFlag="f": Exclude all articles marked with the 'slideshow' attribute, even if they belong to the specified category.- with
flagThe parameters are different,excludeFlagThe parameter can accept multiple recommended attribute characters, separated by commas, for exampleexcludeFlag="f,s"It indicates articles that exclude both 'slideshow' and 'scrolling' attributes.
3. Filter more accurately by combining other parameters
flagandexcludeFlagParameters can be used witharchiveListFlexibly combine other tag 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, you can limit attribute filtering within a specific category. - Sort by (
order): Can be combined withorder="views desc"Display articles with specific attributes and the highest number of views. - Page display (
type="page"): If the number of filtered articles is large, you can use the pagination feature to display them.
For example, display the latest 5 'headlines' 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 that needs to display several articles specially recommended by the editor; at the same time, in the sidebar of the article list page, you would like to display some popular articles, but you do not want the slideshow articles on the homepage to repeat.
Case One: Homepage Featured 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 %}