In the AnQi CMS, efficiently managing and displaying website content is the key to improving user experience and search engine rankings.In order to achieve this goal, we often need to organize and display the document list according to a specific category or content model.archiveListLabels have become a powerful tool in our hands. It can help us flexibly extract the required content from the database and present it in a variety of ways.
archiveListLabel: Conductor of the content list
archiveListThe tag is the core tag used in AnQi CMS template to retrieve and display document lists.Whether it is a blog article, product introduction, news information, or any document under any custom content model, it can accurately filter, sort, and display according to the conditions we set.The power of this tag lies in its flexibility and rich parameter options, allowing us to orchestrate all the content on the website like a conductor.
Let us delve deeper into how to make use ofarchiveListtags to retrieve and display the document list under the specified category and model.
Precise positioning: Filter content through models and categories
In AnQi CMS, a content model (Module) is like a 'mold' for content, defining the structure and fields of different types of content (for example, the 'Article' model may have 'author' and 'publish date' fields, while the 'Product' model may have 'price' and 'stock' fields).And the category (Category) is the 'archive' of content, used for classifying and organizing content of the same type or across types.archiveListTagged throughmoduleIdandcategoryIdThese two key parameters allow us to accurately lock in the target content.
Specify the content model (
moduleId)Firstly, if your website has multiple content types, such as articles and products, you can go throughmoduleIdThe parameter is used to specify which content model's documents to retrieve.Each content model has a unique ID in the background.moduleId="1"(The specific ID should be based on your actual backend configuration)。This is,archiveListit will only pull the data related to articles, ignoring the content of other models.Filter document categories(
categoryId)After determining the content model, we often need to further refine it to one or more specific categories.categoryIdThe parameter allows you to specify one or more category IDs. You can pass a single ID, such ascategoryId="5"Get all documents under the category with ID 5. If you need to get documents from multiple categories, you can separate them with commas, for example,categoryId="5,8,12"A very practical trick is that, when you wantarchiveListInstead of automatically reading the current page's category ID, you can explicitly specify all category documentscategoryId="0"If you are on a category page and want to get the documents under the category and its subcategories, you usually do not need to specify.categoryId,archiveListIt will intelligently read the category information on the current page.
Flexible Display: List Type and Display Quantity
archiveListTags provide various list display types to meet different page requirements:
Non-paginated list (
type="list")When you only need to display a small amount of content on a single page, such as the news headlines on the homepage, popular products in the sidebar, etc., you can usetype="list". In this mode, combinedlimitParameter to control the number of displayed documents, for examplelimit="10"Displays the most recent 10 documents.limitSupports offset mode, such aslimit="2,10"This indicates starting from the 2nd document and retrieving a total of 10 documents.Paging list (
type="page")It is an ideal choice for pages that need to display a large amount of content and require pagination navigation, such as article list pages, product display pages,type="page"in this mode,archiveListAccording to the current page number andlimitparameters (also used to define the number of items displayed per page) automatically handles pagination logic. When usingtype="page", it is usually paired withpaginationThe label is used to generate pagination navigation bars, allowing users to easily browse documents on different pages.Related documents (
type="related")In the document details page, you may want to display some recommended content related to the current document.type="related"It comes into play. It will intelligently recommend similar or related documents based on the keywords or associated settings of the current document.
Sorting and more control
In addition to the above core parameters,archiveListIt also provides a series of parameters to further refine your content list:
Sorting method (
order)You can sort the document according to your needs. Common sorting methods include sorting by ID in reverse order (newest release), such asorder="id desc"; sorting by view count in reverse order (most popular), such asorder="views desc"; as well as sorting by custom fields in the background,order="sort desc".excluding specific categories (
excludeCategoryId)If you need to get all documents under a model or category but want to exclude one or two categories, you can useexcludeCategoryIdparameters, such asexcludeCategoryId="3,7".including subcategory content
child)childThe parameter defaults totrueEnglish, indicates that when retrieving a specified category, documents under its subcategories will also be included. If you only want to retrieve documents for the current category itself (excluding subcategories), you can set it tochild=false.Recommended attribute (
flag)Safe CMS allows setting multiple recommended attributes for documents, such as [h] for headlines, [c] for recommendations, etc. You can useflag="c"to only retrieve documents with the 'Recommended' attribute.
Practice Example: Building Dynamic Document Lists
To better understand the combination of these parameters, let's look at several common practical application scenarios.
Scene one: Display the latest article list under a specific category
Assuming you have a 'Company News' category with a category ID of 8, and you want to display the latest 5 news on the homepage:
<div>
<h3>最新公司新闻</h3>
<ul>
{% archiveList latestNews with moduleId="1" categoryId="8" type="list" limit="5" order="id desc" %}
{% for item in latestNews %}
<li>
<a href="{{item.Link}}">{{item.Title}}</a>
<span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
</li>
{% empty %}
<li>暂无公司新闻。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Here,moduleId="1"Assumed to be an article model,categoryId="8"Specified the "Company News" category,type="list"andlimit="5"Controlled the display quantity,order="id desc"Ensured the content is up-to-date.
Scenario two: Displaying a paginated product list
On a product display page, you may need to display all products per page and provide pagination navigation:
<div class="product-list-container">
{% archiveList products with moduleId="2" type="page" limit="12" order="views desc" %}
{% for item in products %}
<div class="product-item">
<a href="{{item.Link}}">
<img src="{{item.Thumb}}" alt="{{item.Title}}">
<h4>{{item.Title}}</h4>
<p>浏览量: {{item.Views}}</p>
</a>
</div>
{% empty %}
<p>暂无产品信息。</p>
{% endfor %}
{% endarchiveList %}
<div class="pagination-area">
{% pagination pages with show="5" %}
<a href="{{pages.FirstPage.Link}}">首页</a>
{% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
{% for item in pages.Pages %}<a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>{% endfor %}
{% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
<a href="{{pages.LastPage.Link}}">尾页</a>
{% endpagination %}
</div>
</div>
In this example,moduleId="2"Assuming a product model,type="page"Pagination is enabled,limit="12"12 products per page are defined,order="views desc"Then sort by view count in descending order. SubsequentpaginationGenerated complete pagination links for tags.
Scenario three: complex multi-level classification and document mixed display
Assuming you need to display the top-level categories (such as "Solutions") and their subcategories on the homepage, and the corresponding product documents under each subcategory. If there are no subcategories, directly display the product documents under the top-level category.
<div class="category-product-display">
{% categoryList topCategories with moduleId="2" parentId="0" %} {# 获取顶级产品分类 #}
{% for topCat in topCategories %}
<section>
<h2><a href="{{topCat.Link}}">{{topCat.Title}}</a></h2>
<div class="sub-category-or-products">
{% if topCat.HasChildren %} {# 如果有子分类,则显示子分类 #}
{% categoryList subCategories with parentId=topCat.Id %}
{% for subCat in subCategories %}
<div class="sub-category-block">
<h3><a href="{{subCat.Link}}">{{subCat.Title}}</a></h3>
<ul>
{% archiveList subCatProducts with type="list" categoryId=subCat.Id limit="4" %} {# 显示子分类下的产品 #}
{% for product in subCatProducts %}
<li><a href="{{product.Link}}">{{product.Title}}</a></li>
{% empty %}
<li>暂无产品。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
{% endfor %}
{% endcategoryList %}
{% else %} {# 如果没有子分类,直接显示顶级分类下的产品 #}
<ul>
{% archiveList topCatProducts with type="list" categoryId=topCat.Id limit="8" %}
{% for product in topCatProducts %}
<li><a href="{{product.Link}}">{{product.Title}}</a></li>
{% empty %}
<li>暂无产品。</li>
{% endfor %}
{% endarchiveList %}
</ul>
{% endif %}
</div>
</section>
{% endfor %}
{% endcategoryList %}
</div>
This example demonstratesarchiveListWithcategoryListnested usage of tags, combined withifcondition judgment to handle the different display logic for whether there are child categories, greatly enhancing the dynamicity and flexibility of the template.
Summary
archiveListLabels are a powerful foundation of AnQi CMS content operation. By mastering its various parameters, and combining with other auxiliary labels (such ascategoryDetail/paginationYou can easily build clear, powerful, and diverse content-rich web page structures.Flexibly using these tags will help enhance the content organization capability and user browsing experience of your website.
Common Questions (FAQ)
Q1: How do I know the ID or content model ID of a category?
A1:In the AnQi CMS backend, you can easily find these IDs.
ForCategory IDEnter 'Content Management' -> 'Document Categories', and you will usually see the ID next to each category name in the category list. Or you can click 'Edit' to enter the detail page.Content Model IDEnter "Content Management" -> "Content Model", and the ID of each model will also be displayed next to its name in the model list. These IDs are what you use in the template.moduleIdandcategoryIdThe basis when parameterizing.
Q2:type="list"andtype="page"When usingarchiveListWhat are the core differences when labeling?
A2:The main difference lies in whether pagination logic is handled.type="list":主要用于获取一个固定数量的文档列表,不涉及分页。您需要通过limit参数明确指定要显示的文档数量。如果文档数量超出limitThe excess documents will not be displayed, and there will be no pagination navigation.type="page":用于获取支持分页的文档列表。它会根据当前的URL参数(如页码)自动计算并显示当前页的文档,并提供总页数、当前页