As an experienced website operations expert, and deeply familiar with AnQi CMS, I fully understand that how to efficiently obtain and display content is the core aspect of building a website. Today, let's delve into an extremely important and powerful tag in the AnQi CMS template -archiveListIt can help us flexibly obtain various document lists, providing endless possibilities for website content presentation.
Core Function Overview:archiveListfunction
In the Anqi CMS,archiveListTags are the foundation of content display.It is not just a simple document list retrieval tool, but also a multifunctional "content scheduler".archiveListcan all handle with ease.
Imagine, there is a 'Latest News' section on your website that needs to display the latest ten articles; or below the product details page, a few 'related products' need to be recommended; or on a category page, all articles under the category need to be presented in a paginated form. The acquisition and display of these dynamic contents cannot be separated fromarchiveListThe exquisite application of 【en】.
Basic syntax and getting started: how to call 【en】.archiveList
archiveListThe use of tags follows the unified style of the security CMS template engine, namely, with 【en】.{% %}wrapped, and through 【en】.withPass parameters by keywords. Its basic structure is concise and clear:.
{% archiveList 变量名称 with 参数 %}
{% for item in 变量名称 %}
{# 在这里展示文档内容 #}
{% empty %}
{# 如果没有内容,显示此段落 #}
{% endfor %}
{% endarchiveList %}
Here,变量名称is a variable you define yourself, for example.archivesorarticles.archiveListThe tag will store the list of documents obtained in this variable, and then you can use it inforIterate through this variable in the loop and display the detailed information of each document one by one.{% empty %}A clause is a very thoughtful design that elegantly displays a prompt message when the list is empty, rather than making the page look empty.
Deep Understanding:archiveListcommon parameters
archiveListThe power of tags lies in their rich parameter options.By combining these parameters, you can precisely control the range and presentation of the documents you want to retrieve.
Locate content range:
moduleIdWithcategoryIdmoduleIdSpecify the document of the content model you wish to retrieve. For example,moduleId="1"may represent the article model, whilemoduleId="2"may represent the product model. This allows you to easily switch between different types of content.categoryIdIf you only want to retrieve documents under a specific category, you can use this parameter. For example,categoryId="5"Retrieve all documents under the category with ID 5. If you need to retrieve documents from multiple categories, you can separate them with a comma, likecategoryId="1,2,3"It is worth mentioning that if set tocategoryId="0"Or completely omit this parameter,.archiveListIt will try to get the documents of the current page category or all categories, depending on the coordination of other parameters.excludeCategoryId: withcategoryIdOn the contrary, used to exclude documents of specified categories.parentIdWhen you want to get child documents under a parent document, this is very useful when building hierarchical content such as project cases, multi-step tutorials, etc.
Filter content properties:
flagWithexcludeFlagThe Anqi CMS supports setting various recommended attributes for documents (such as headline [h], recommended [c], slideshow [f], etc.).flag: Throughflag="c"You can only get documents marked as 'recommended'.excludeFlag[en]: Used to exclude documents with specific attributes, such asexcludeFlag="h"The headline article will not be displayed.showFlag[en]: If you need the flag attribute of the documents in the list to be displayed, please set it toshowFlag=true.
Sorting and Limiting:
orderWithlimitorderDetermines the sorting method of the document. Common values include:id desc(Sorted by ID in reverse order, usually the most recent publications),views desc(Sorted by view count in reverse order, popular articles),sort desc(Sorted by custom order in the background). You can choose the most suitable sorting method according to your needs.limit: Controls the number of documents returned.limit="10"It will only retrieve 10 documents. It also supportsoffsetpattern, such aslimit="2,10"Indicates fetching 10 records starting from the second one, which is very suitable for skipping the first few records for display.
Display Mode:
typetypeParameter isarchiveListis one of the core features, defining the type of presentation for the document list:type="list"Default mode, retrieves the specified number of documents without involving pagination. Suitable for sidebars, recommendation lists, etc.type="page"Page mode. When you need to display a large number of documents in multiple pages, this type must be used. It works withpaginationtag to generate page links.type="related"Document mode related. Usually used on detail pages, intelligently recommending related content based on the current document's category, keywords, or backend settings.
Dynamic search and filtering:
qWith custom filter parametersq: to implement search functionality. For example,q="关键词"only documents with the keyword in the title will be displayed. Whentype="page"whenarchiveListwill automatically read the parameters in the URL.qparameter to perform the search.- Custom filter parameters: If you define filterable fields (such as "Gender
archiveListPerform advanced filtering, such assex=男.
Multiple sites and combined documents:
siteId/combineIdWithcombineFromIdsiteIdIf you have enabled the multiple sites feature, you cansiteIdspecify which site to retrieve documents from.combineId/combineFromIdThis is a very unique and powerful feature of Anqi CMS, used to achieve 'combination comparison' of documents.For example, on travel route websites, you can combine the travel information of 'Beijing' and 'Shanghai' into a 'travel route from Beijing to Shanghai', and obtain the data of these two documents in the template for comparison and display.
Data access:archiveListFields available in the loop
OncearchiveListFill the data into your custom variable (for example)archives), and you can access various properties of each document.forin the loop byitemCommon fields include:
item.Id: Document ID.item.Title: Document title.item.Link: Document link.item.Description: Document summary.item.LogoThe document cover main image (usually the full-size thumbnail).item.ThumbThe document cover thumbnail.item.Views: Document view count.item.CreatedTimeThe document creation time (timestamp, which needs to be paired withstampToDateFilter formatting).item.UpdatedTime【en】Document update time (timestamp, which needs to be formatted as well).item.CategoryId【en】Document category ID.- and all the custom fields defined in the content model, you can access them directly by
item.自定义字段名to access.
Time formatting promptDue toCreatedTimeandUpdatedTimeit is a timestamp, you need to usestampToDatea filter to convert it to a readable date format, such as{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}.
Practical scenarios and examples
To help you better understandarchiveListthe actual application of