In the AnQi CMS template system,archiveListTags are the core tool for building dynamic content lists. Whether it is a list of blog articles, a product display page, or a news information module,archiveListCan help you accurately filter, sort, and present content according to diverse needs, making your website content area come alive.
archiveListFundamentals: Understanding how it works.
UsearchiveListWhen labeling, you first need to define a variable to receive the article data you get, for examplearchives. Then throughforLoop through this variable, display the detailed information of each article. The basic structure is usually like this:
{% archiveList archives with type="list" limit="10" %}
{% for item in archives %}
<!-- 在这里展示每篇文章的信息,例如标题、链接、简介等 -->
<a href="{{item.Link}}">{{item.Title}}</a>
<p>{{item.Description}}</p>
{% empty %}
<!-- 如果没有找到文章,将显示这里的内容 -->
<p>暂时没有相关内容。</p>
{% endfor %}
{% endarchiveList %}
here,type="list"Means we want to get a normal list,limit="10"The number of displayed articles is limited.{% empty %}Tags are a very practical feature. When the list is empty, you can elegantly display a prompt message instead of leaving the page blank.
Precise positioning: Filter articles based on categories
In many scenarios, we may need to display articles under specific categories, such as 'Company News' or 'Industry Dynamics'.archiveListTag throughmoduleIdandcategoryIdThe parameter can very conveniently meet this requirement.
first, moduleIdThe parameter is used to specify the type of content model you want to obtain, such as the article model (usually)moduleId="1") or product model (usually)moduleId="2"This is the foundation, ensure you are operating under the correct model.
Then,categoryIdThe parameter allows you to specify one or more category IDs. If you want to get the ID of5articles under the category, you can set it like this:
{% archiveList archives with moduleId="1" categoryId="5" limit="10" %}
<!-- 展示文章列表 -->
{% endarchiveList %}
If you want to get articles from multiple categories at the same time, for example, with ID:5and8categories, just separate them with commas:categoryId="5,8".
Moreover, if you want to display only the articles of the current category and not include the content of its subcategories, you can usechild="false"parameters:
{% archiveList archives with moduleId="1" categoryId="5" child="false" limit="10" %}
<!-- 仅显示ID为5的分类下的文章,不包含子分类文章 -->
{% endarchiveList %}
By combining these parameters, you can flexibly control the source of the articles.
Highlight the key points: Use recommended attributes to display specific content
The AnQi CMS backend allows you to set various recommended properties for articles, such as 'Top [h]', 'Recommended [c]', 'Slideshow [f]', and so on.These properties are very useful in website operations and can help highlight important content in specific areas.archiveListTag throughflagParameters, can easily filter out articles with these attributes.
For example, to display 'Recommended' articles in a module on the homepage, you can use it like thisflag="c":
{% archiveList archives with moduleId="1" flag="c" limit="5" %}
<!-- 展示5篇推荐文章 -->
{% endarchiveList %}
If you want to display the recommended attribute tags of articles in the article list at the same time, for example, displaying an icon such as "recommended" or "headline", you canarchiveListSet in the labelshowFlag="true". Thenforgo through the loop inside{{item.Flag}}Get the recommended attribute code for the article and process the style or icon accordingly.
{% archiveList archives with moduleId="1" showFlag="true" limit="5" %}
{% for item in archives %}
<h3>
<a href="{{item.Link}}">{{item.Title}}</a>
{% if item.Flag == 'h' %}<span class="flag-headline">头条</span>{% endif %}
{% if item.Flag == 'c' %}<span class="flag-recommend">推荐</span>{% endif %}
</h3>
{% endfor %}
{% endarchiveList %}
This article with the 'headline' or 'recommended' attribute can be prominently displayed on the page.
Orderly: Implementing custom sorting of articles
The way articles are sorted directly affects the reading experience of users.archiveListTags provide a variety oforderparameter values, allowing you to adjust the order of articles according to your actual needs.
The most commonly used sorting methods include:
id desc: Sorted in descending order by article ID, which usually means the most recent articles are at the top.views descThe articles are usually displayed in descending order of view count, showing the most popular articles.sort desc: Sort in descending order by the "display order" field defined in the background. This means you can manually adjust the order of articles in the background, which is very suitable for manual management of recommended content.
For example, if you want to display the latest articles in a certain area and limit the number to 8, you can write it like this:
{% archiveList archives with moduleId="1" order="id desc" limit="8" %}
<!-- 展示8篇最新文章 -->
{% endarchiveList %}
In order to display the most popular articles on the website, you can sort by page views:
{% archiveList archives with moduleId="1" order="views desc" limit="10" %}
<!-- 展示10篇最热门文章 -->
{% endarchiveList %}
Integrate knowledge: Use multiple conditions in combination
archiveListThe true strength of the tag lies in its flexible parameter combination. You can use it simultaneously tomoduleId/categoryId/flagandorderbuild a very precise list of articles.
For example, to get the ID of5In the category, the top 10 articles with the 'recommended' attribute, sorted by views in descending order:
{% archiveList archives with moduleId="1" categoryId="5" flag="c" order="views desc" limit="10" %}
<!-- 展示特定分类下推荐且热门的文章 -->
{% for item in archives %}
<h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
<p>浏览量: {{item.Views}}</p>
{% endfor %}
{% endarchiveList %}
You can also useexcludeCategoryIdandexcludeFlagParameters to exclude specific categories or recommended attributes, further refining your content filtering.
###