AnQiCMS content management: usingarchiveListPrecisely obtain the document list with tags
As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its ability to organize and display content. In the AnQiCMS, a high-efficiency and flexible Go language content management system,archiveListTags are undoubtedly a powerful weapon in the content display process.It is not just a simple content call tag, but also a key bridge connecting your website content model with the front-end display logic.archiveListLabel, accurately and efficiently retrieve the document list under the specified content model.
archiveList: The core of AnQiCMS content display.
AnQiCMS is inv2.1.1An important label restructuring was performed in the version, removing the originalarticleandproductand specific labels were introduced uniformlyarchiveThe series of tags, and fully embraced the concept of Content Model.This means that all articles, products, and even any content type you customize are uniformly classified as "documents (archive)" and distinguished and managed through their respective content models.archiveListTags are the core of this system, allowing you to flexibly display the document list you need on the website front-end based on different content models, categories, attributes, and other conditions.
Its strength lies in the ability to dynamically load and display content on different page templates (such as the homepage, list page, special page) according to business needs, whether it is news articles, product introductions, event information, or case studies.archiveListCan do it effortlessly.
Core parameter analysis: accurately locate your content.
To usearchiveListLabel, you need to wrap it in aforIn a loop, because its purpose is to return a collection of documents. The basic structure is as follows:
{% archiveList archives with ... %}
{% for item in archives %}
{# 在这里展示每个文档的具体信息 #}
{% empty %}
{# 如果列表为空,则显示此内容 #}
{% endfor %}
{% endarchiveList %}
Among them,archivesis the variable name you define for the document list,itemIt represents the variable for each document in the loop.withThe parameters behind it are the key to accurately locate the content.
moduleId- Content model, the cornerstone of documentsmoduleIdIsarchiveListA parameter that is crucial in the label.It explicitly tells the system which content model you want to retrieve the document from.AnQiCMS allows you to customize content models, for example, you can create 'article models', 'product models', 'case models', etc.- How to obtain
moduleId?In the AnQiCMS backend, go to 'Content Management' -> 'Content Model', and you will see that each model has a unique ID. For example, the default 'Article Model' usually has an ID of1,“Product model”usually has an ID of2.When customizing a model, you can also record the corresponding ID. - Example:If you want to get the document list under all article models, you can write it like this:
moduleId="1".
- How to obtain
categoryId- Accurately locate the classification of contentWhen there are multiple classifications under your content model,categoryIdParameters can help you further narrow down the scope, only fetching documents under specified categories or multiple categories.- Example:Get the category ID of
5article list:categoryId="5" moduleId="1". - Multiple categories:Get the category ID of
5/6/7article list:categoryId="5,6,7" moduleId="1". - Current category:If not specified
categoryId,archiveListThe default behavior is to try to read the category ID of the current page. If you want it not to read the current category automatically, you can explicitly setcategoryId="0". - Exclude categories:Use
excludeCategoryId="8"You can exclude ID as8documents under the category.
- Example:Get the category ID of
type- The diversity of list presentation.typeThe parameter defines what you want.archiveListHow to return document data, it has several common values:type="list"(Default): Get a fixed number of document lists, usually used for sidebar recommendations, latest content on the homepage, etc.type="page": Used for displaying document lists with pagination. When using this type, you need to配合paginationtags to generate pagination navigation.type="related": Used to retrieve the document list related to the current document.This is commonly used on the document detail page, AnQiCMS will automatically match related content based on the current document's category, keywords, etc.like="keywords"orlike="relation"Further refine related rules.
orderandlimit- Sorting and quantity control of resultsorder:Control the sorting method of documents. Common values include:order="id desc":Sort by document ID in reverse order (latest released).order="views desc":Sort by views in reverse order (most popular).order="sort desc": Sort by custom backend (default).
limit:Control the number of documents retrieved.limit="10": Retrieve 10 documents.limit="2,10"Starting from the 2nd item, retrieve 10 documents (often used to skip the first few).
Other commonly used parameters: finer filtering
flag:Based on the recommended properties of the document (such as头条h, recommendedcof slidesffiltered. For exampleflag="c"Get recommended documents.q:Search keywords. Only intype="page"it is effective, and can be used for fuzzy search in document titles.siteId:Under the multi-site management mode, specify which site's data to retrieve. Generally, it is not necessary to fill in.child="false":By default,archiveListIt will simultaneously retrieve documents under the specified category and its subcategories. If you only want to retrieve documents under the current category, you can setchild="false".userId/parentId/combineId/combineFromId:Used for more professional filtering needs, such as by author, parent document, combined document, etc.
Practical exercise:archiveListApplication scenarios
Now, let's show several common application scenarios through several examples.archiveListThe powerful function.
Scenario one: Display the latest published article list on the homepage.
Assuming your article model ID is.1.
`twig
<h2>最新文章</h2>
<ul>
{% archiveList archives with moduleId="1" type="list" order="id desc" limit="8" %}
{% for item in archives %}
<li>