As an experienced website operations expert, I know that the powerful function of the Content Management System (CMS) lies in its flexibility and ease of use.In AnQiCMS (AnQiCMS), the 'Recommended Attribute' (Flag) of the document is such a seemingly simple feature, but it can greatly improve the efficiency of content operation and the diversity of website display.Today, let's delve into how to skillfully use recommendation attributes to achieve precise filtering and display of document lists.
Understanding the 'recommended attributes' (Flag) of Anqi CMS
In Anqi CMS, when we publish or edit a document, in addition to the basic information such as title, content, and category, we will also see a very practical option called 'Recommended Properties'.These properties are like special tags applied to documents, which do not affect the document's classification, but are used to mark the characteristics or importance of the document so that it can be displayed or filtered specially on the website front-end.
AnQi CMS provides eight preset recommended attributes, you can select one, multiple, or even none for documents according to actual operational needs. These attributes correspond to simple letter identifiers, they are:
- Headline [h]: It is usually used to mark the most important articles that need to be highlighted.
- Recommend [c]: Indicates that the content quality is high and worth recommending to users.
- Slide [f]:Used for documents displayed in slideshows or carousels, images are usually the focus.
- Special recommendation [a]:Documents with special significance or those that need to be particularly recommended.
- Scroll [s]: Suitable for displaying brief information on bulletin boards or scrolling news.
- Bold [h]: Hint to the front-end to bold the title or other text to emphasize when displayed.
- Image [p]Indicates that the document primarily contains images or emphasizes the display of images.
- Jump [j]Used to mark special documents that will jump to external links instead of the document details page when clicked.
These settings are very intuitive, located in the "Content Management" module on the back end. When you add or edit documents, you can find the "Recommended Properties" option to check on the interface.
Core Tool:archiveListThe clever use of tags
In AnQi CMS template design, we mainly usearchiveListTag to retrieve and display a list of documents. This tag is powerful, supporting various parameters to control the source, sorting, and display method of the list. To filter documents based on recommended properties,flagandexcludeFlagThese two parameters are the core of our matter.
archiveListThe basic usage of the tag is like this:
{% archiveList 变量名称 with 参数1="值1" 参数2="值2" %}
{% for item in 变量名称 %}
{# 在这里循环显示文档内容 #}
{% endfor %}
{% endarchiveList %}
Among them,变量名称It is a name you customize for the document list you obtain, for examplearchives/latestNewsetc.
Guide to practical application: Filtering documents based on recommended attributes
Now, let's see how to actually apply these recommended attributes to filter and display documents in a template.
1. Filter documents showing specific recommended properties
Assuming you want to display only those documents marked as 'Top News' in a specific area of the homepage. You can useflagParameters, and pass the corresponding letter identifier.
{# 示例:在首页显示5篇“头条”文档 #}
<div class="headline-articles">
<h2>今日头条</h2>
<ul>
{% archiveList headlines with flag="h" limit="5" %}
{% for item in headlines %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% empty %}
<li>暂无头条文章。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
In this example,flag="h"TellarchiveListThe tag only retrieves documents with the 'Top News' attribute.limit="5"This limits the number of displayed items to 5.{% empty %}A block is a very friendly design, when there are no documents that meet the conditions, it will display 'No headline articles available', to avoid the page from being blank.
2. Exclude documents with specific recommendation attributes.
Sometimes, you might want to display the vast majority of documents but exclude certain specific attributes.For example, you have a regular list of articles, but you don't want documents marked as "slide" to appear here because they have already been displayed in the carousel area.excludeFlagThe parameters come into play.
{# 示例:显示最新文章,但排除掉“幻灯”文档 #}
<div class="latest-articles">
<h2>最新动态</h2>
<ul>
{% archiveList regularContent with excludeFlag="f" order="id desc" limit="10" %}
{% for item in regularContent %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% empty %}
<li>暂无最新动态。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
here,excludeFlag="f"Documents with the 'slide' attribute were ensured not to appearregularContentin the list.order="id desc"Then, documents are displayed in reverse chronological order, showing the most recent ones.
3. Display recommended property indicator in document list
If you want users to see at a glance that a document has special recommended attributes, you can display a mark next to the document title.archiveListTags providedshowFlag=trueA parameter that includes all recommended attribute letter strings (such as "hc") in the documentitem.Flagin the field.
”`twig {# Example: Display recommended documents and note properties next to the title #}
<h2>精选推荐</h2>
<ul>
{% archiveList featuredDocs with flag="c" showFlag=true limit="5" %}
{% for item in featuredDocs %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
{% if item.Flag %}
<span class="doc-flag">[{{ item.Flag }}