In 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 document lists according to specific categories or content models. At this point,archiveListTags have become a powerful tool in our hands. They can help us flexibly extract the required content from the database and present it in a variety of ways.
archiveListTag: The conductor of the content list.
archiveListThe tag is the core tag in Anqi CMS template, used to obtain and display document lists.No matter whether it is a blog post, product introduction, news information, or any document under a custom content model, it can be precisely filtered, sorted, and displayed according to the conditions we set.The strength 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's delve into how to make use ofarchiveListtags to retrieve and display the document list under specified categories and models.
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', 'publish date' fields, and the 'product' model may have 'price', 'inventory' fields).And the category (Category) is a 'filing cabinet' for content, used for classifying and organizing content of the same type or across types.archiveListTag throughmoduleIdandcategoryIdThese two key parameters allow us to accurately lock in the target content.
Specify content model (
moduleId)First, if your website has multiple content types, such as articles and products, you can go throughmoduleIdThe parameter specifies which content model's documents to retrieve. Each content model has a unique ID in the background.For example, if you want to retrieve all documents of the "Article" model, you would typically setmoduleId="1"(The specific ID should be configured according to your backend settings). This,archiveListit will only pull data related to articles, ignoring content from other models.Filtering 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"Retrieve all documents under the category with ID 5. If you need to retrieve documents from multiple categories, you can separate them with commas, for example,categoryId="5,8,12". A very practical skill is, when you wantarchiveListDo not automatically read the category ID of the current page, but get all category documents explicitly.categoryId="0"On the contrary, if you are on a category page and want to retrieve the documents under the category and its subcategories, it is usually not necessary to specifycategoryId,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 needs:
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, combinelimitParameters to control the number of documents displayed, for examplelimit="10"It will display the most recent 10 documents.limitIt also supports offset mode, such aslimit="2,10"which means starting from the 2nd document and retrieving a total of 10 documents.Pagination list (
type="page")For pages that need to display a large amount of content and require pagination navigation, such as article list pages and product display pages,type="page"it is an ideal choice. In this mode,archiveListBased on the current page number andlimitparameters (which are also used to define the number of items displayed per page) automatically handles pagination logic. When usingtype="page", it is usually paired withpaginationTags are used to generate pagination navigation bars, allowing users to easily browse documents on different pages.Related documents (
type="related")On the document detail page, you may want to display some recommended content related to the current document. At this time,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 aforementioned core parameters,archiveListIt provides a series of parameters to further refine your content list:
Sorting method (
order)You can sort the documents according to your needs. Common sorting methods include sorting by ID in reverse order (latest release), such asorder="id desc"; sorting by views in reverse order (most popular), such asorder="views desc"; as well as sorting by the custom sorting field in the background, such asorder="sort desc".excluding specific categories(
excludeCategoryId)If you need to get all documents under a certain model or category but want to exclude one or two categories, you can useexcludeCategoryIdparameters, for exampleexcludeCategoryId="3,7".Including content with subcategories (
child)childThe parameter is set to default.trueThis indicates that when fetching a specified category, it will also include the documents under its subcategories. If you only want to fetch the documents of the current category (without its subcategories), you can set it tochild=false.Recommended attributes (
flag)The AnQi CMS allows you to set various recommendation attributes for documents, such as headline[h], recommendation[c], etc. You can useflag="c"to retrieve documents with the 'recommendation' attribute.
Example Practice: Building a Dynamic Document List
To better understand the combination of these parameters, let's look at several common practical application scenarios.
Scenario one: Display the latest articles under a specific category
Assuming you have a 'Company News' category with ID 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 number of displayed items,order="id desc"Ensure that the content is up-to-date.
Scenario two: Display paginated product lists.
On a product display page, you may need to display all products page by 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"Define 12 products per page,order="views desc"Then sort in descending order by page views. The subsequentpaginationThe tag generates a complete pagination link.
Scenario three: complex multi-level classification and mixed document display
Suppose you need to display the top-level categories (such as "Solutions") and their subcategories on the homepage, and display the corresponding product documentation under each subcategory. If there are no subcategories, directly display the product documentation 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 shows.archiveListwithcategoryListNested tags are used and combined withifConditional judgment is used to handle different display logic for subcategories, greatly enhancing the dynamism and flexibility of the template.
Summary
archiveListTags are a powerful foundation for Anqi CMS content operation. By mastering its various parameters, and combining with other auxiliary tags such ascategoryDetail/paginationYou can easily build clear, powerful, and diverse web page structures.Apply these tags flexibly to help enhance the content organization and user browsing experience of your website.
Frequently Asked 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 Category", where the ID of each category is usually displayed next to the name in the category list, or you can click "Edit" to enter the detail page to see it as well.
ForContent model IDEnter "Content Management" -> "Content Model", the ID of each model will also be displayed next to its name in the model list. These IDs are used in the template.moduleIdandcategoryIdThe basis when parameterizing.
Q2:type="list"andtype="page"While usingarchiveListWhat are the core differences when labeling?
A2:The main difference is whether pagination logic is handled.type="list"This is mainly used to get a fixed number of document lists without involving pagination. You need to specify the number of documents to display through thelimitparameter. If the number of documents exceedslimitThe redundant documents will not be displayed, and there will be no pagination navigation.type="page"It is used to obtain a paginated list of documents. It automatically calculates and displays the documents of the current page based on the current URL parameters (such as page number) and provides the total number of pages, the current page