AnQiCMS as an efficient enterprise-level content management system, provides users with flexible and diverse content management and display capabilities.When building a website, we often need to display document lists based on specific conditions, such as only showing articles in a certain category, or only listing entries of specific content models (such as products, services). At this point,archiveListTags have become the tool in our hands. They are not only powerful but also very intuitive to use, making it easy for us to meet these needs.
archiveList: Get the core tags of the document list
archiveListThe tag is used in the AnQiCMS template system to query and display the list of 'documents'.Here, the term "document" is a general concept, which can be articles on your website, product information, news updates, or even any entries in a custom content model.Through flexible configurationarchiveListThe parameter, we can accurately control which content needs to be displayed.
Its basic usage is usually like this:
{% archiveList 变量名称 with 参数="值" %}
{% for item in 变量名称 %}
<!-- 在这里显示每个文档的具体信息 -->
{% endfor %}
{% endarchiveList %}
Amongst which, "variable name" is a custom name we use for the document list obtained, for examplearticlesorproducts, later inforthe loop you can pass throughitem(or any other loop variable) to access each document data in the list.
Filter by content model: define the boundaries of the content.
One of the highlights of AnQiCMS is its flexible content model.You can create different content models based on business needs, such as "article model", "product model", "case model", and so on.When you want to display documents under a specific model only,archiveListlabel'smoduleIdParameters can be put to good use.
moduleIdThe parameter allows you to specify which content model's document list to retrieve. Each content model has a unique ID in the background. For example, suppose the ID of the "article model" is1And the ID of the 'Product Model' is2. If you want to display the latest 5 'articles' on the page, you can write it like this:
{% archiveList articles with moduleId=1 limit=5 %}
{% for item in articles %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endfor %}
{% endarchiveList %}
By usingmoduleIdis set to1,archiveListit will cleverly only retrieve data from the "article model". Similarly, if you need to display the content under the "product model", just replacemoduleIdwith the corresponding ID.
Filter by category: precisely locate the content range
In addition to filtering by content model, we often encounter the need to display documents based on content categories.For example, on the article list page, we may only want to display all articles under the "CMS Tutorial" category.archiveListofcategoryIdThe parameter is born for this.
You can usecategoryIdSet the ID of a category. For example, if the ID of the "CMS tutorial" category is10You can get the document list under this category like this:
{% archiveList tutorialArticles with categoryId=10 limit=10 %}
{% for item in tutorialArticles %}
<h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
<p>{{ item.Description }}</p>
{% endfor %}
{% endarchiveList %}
categoryIdThe parameter supports not only a single category ID, but also multiple category IDs, separated by commas,separated. This way, you can display documents from multiple specified categories at once:
{% archiveList mixedContent with categoryId="10,12,15" limit=10 %}
{% for item in mixedContent %}
<p>来自分类ID {{ item.CategoryId }}:<a href="{{ item.Link }}">{{ item.Title }}</a></p>
{% endfor %}
{% endarchiveList %}
Sometimes, we may need to exclude certain categories, and in such cases, we can useexcludeCategoryIdParameter. For example, you want to display all articles but exclude articles with ID10and11Category:
{% archiveList allButExcluded with moduleId=1 excludeCategoryId="10,11" limit=10 %}
{% for item in allButExcluded %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endfor %}
{% endarchiveList %}
It is worth mentioning that categories are often hierarchical (with parent categories and subcategories).archiveListThe default setting will display the current category and all its subcategory documents. If you only want to display the documents directly contained in the current category, and not include the documents of its subcategories, you can setchild=false:
{# 只显示分类ID为10的直接文档,不包含其子分类 #}
{% archiveList directArticles with categoryId=10 child=false limit=10 %}
{% for item in directArticles %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endfor %}
{% endarchiveList %}
Combine filtering conditions: achieve more complex queries
archiveListThe strength lies in the fact that you can flexibly combine the above filtering conditions with other parameters to achieve more refined document queries.
- Recommended properties (
flag): If you have set attributes such as 'Top Story', 'Recommended', 'Slideshow' in the background of the document, you can filter through parameters. For example, display all articles marked as 'Recommended':flagparameter to filter. For example, show all articles tagged as 'Recommended':{% archiveList recommendedArticles with moduleId=1 flag="c" limit=5 %} {% for item in recommendedArticles %} <li><a href="{{ item.Link }}">[推荐] {{ item.Title }}</a></li> {% endfor %} {% endarchiveList %} - Sort method (
order)You can arrange the list according to the document ID (newest release), views (most popular), or custom sorting on the backend. For example, sort by views in descending order:{% archiveList hotArticles with moduleId=1 order="views desc" limit=5 %} {% for item in hotArticles %} <li>{{ item.Title }} ({{ item.Views }} 阅读)</li> {% endfor %} {% endarchiveList %} - Show number (
limit): Control how many documents are displayed in the list. You can also useoffset,limitFormat to skip the first few and get a specified number of items. For example, start from the 2nd item and get 5 items:limit="2,5". - List type (
type): Besides the defaultlistType (fixed number),type="page"Used to cooperatepaginationTags can be used to implement pagination, andtype="related"It is used to get the relevant documents of the current document. - When searching for keywords (
q):Whentype="page"can be combined withqThe parameter performs keyword search, it will be based on the URL inqThe parameter automatically matches the title