In AnQi CMS,archiveListTags are the core tools for building dynamic content lists, allowing you to flexibly extract and display the content you want from the document library of the website. Whether it's displaying the latest articles under a specific category, popular products under a specific content model, or special document series with specific recommendation attributes, archiveListCan be achieved through its rich parameter configuration, helping you to accurately meet these needs.
Accurately locate content: categories, models and recommended attributes
Firstly, let's understandarchiveListThe most commonly used dimensions for filtering content: classification, content model, and recommendation properties.
1. Filter documents by category (categoryId)
The content of a website is usually categorized into different categories according to its theme, such as "Company News", "Industry Dynamics", or "Product Introduction", etc.archiveListTags can be used tocategoryIdParameters allow you to easily specify which or which categories of documents to display.
- Specify a single or multiple categoriesIf you want to display documents under a specific category (for example, ID 10), you can use it like this:
{% archiveList archives with categoryId="10" %}If you need to display documents under multiple categories (such as IDs 10, 12, 15), just separate them with commas:{% archiveList archives with categoryId="10,12,15" %}. - Control subcategory contentIn some cases, you may only want to display the documents of the current category itself, without including the content of its subcategories. In this case,
child="false"the parameter comes into play. By default,archiveListIt will include sub-categories. If you only want the documents of the current category (ID 10), you can write it like this:{% archiveList archives with categoryId="10" child="false" %}. - It does not depend on the current page category: Sometimes, even if you are on the category page, you may not want
archiveListto automatically read the category ID of the current page. At this time, you can explicitly setcategoryId="0"Stop this automatic behavior and specify the category ID you need to filter.
2. Filter documents by content model (moduleId)
The key feature of Anqi CMS is its flexible content model mechanism, which allows you to define independent field structures for different types of content (such as articles, products, cases, etc.).archiveListTag throughmoduleIdParameters, allow you to accurately filter out documents belonging to a specific content model.
- Identify the content modelIn the Anq CMS backend, you can create content models for different content types (for example, the system default "article model" and "product model").Each content model has a unique ID. By specifying this ID,
archiveListOnly documents under the model can be displayed. For example, if you want to display documents under the product model and the product model ID is 2, you can use it like this:{% archiveList products with moduleId="2" %}. - Combine categories and modelsYou can also use
moduleIdandcategoryIdCombined use, for example, to display a list of products under a certain category that belong to a product model.
3. Filter documents by recommended attributes (flag)
When publishing documents, AnQi CMS provides various recommended attributes such as "headline", "recommended", "slide" etc., which are identified by different letters (for example,hrepresenting the headline,cRepresents recommendation).archiveListTags can be used toflagParameters, filter content based on these properties.
- Specify recommendation properties: If you want to display all documents marked as 'recommended' on the homepage, you can use it like this:
{% archiveList featuredDocs with flag="c" %}You can combine multiple properties, for exampleflag="h,c"Documents that are both headlines and recommended will be displayed. - Exclude specific attributes: If you want to exclude documents with certain specific properties, you can use
excludeFlagthe parameters. For example,{% archiveList normalDocs with excludeFlag="h" %}It will display all non-headline documents. - Display attribute identifier: If you need to display the recommended attributes of documents in the list, you can
archiveListthe tag withshowFlag="true"Parameter.
Expand filtering capabilities: more practical parameters
In addition to the above core filtering criteria,archiveListit also provides a variety of other parameters to further optimize your content list:
- Sort method (
order)You can sort the documents according to document ID (latest released), views (most popular), or custom sorting on the backend. For example,order="id desc"means in descending order by ID (latest release),order="views desc"means sorted by views in descending order. - Show number and pagination (
limit,type="page"):limitParameters are used to control how many documents are displayed. If you need to implement pagination, you can usetypethe parameter to"page"and combiningpaginationtags to create a complete pagination navigation. - When searching for keywords (
q): on the search results page,qThe parameter can be used to match the content of the document title that contains specific keywords. If the URL already containsqparameter,archiveListit will be automatically read and applied. - Custom Filter Parameter: AnQi CMS allows you to define custom fields for content models in the background. If these fields are set to be filterable,
archiveListYou can further filter based on the query parameters in the URL, which is very useful for creating highly customized filter interfaces (such as property websites filtering by area, type, etc.). You can combinearchiveFiltersTags to build these filtering conditions. - Multi-site data call (
siteId): If you use the multi-site management function of Anqi CMS,siteIdthe parameter allows you to call data from other sites. - Combination document display (
combineId,combineFromId)This is an advanced usage, used to display multiple documents in a list, such as showing 'Travel routes from A to B', which can dynamically combine document titles and links, often used in scenarios of comparison or combination of information.
Example of practical application scenarios
Let us go through several common scenarios and seearchiveListhow tags play a role:
Scenario one: Display the latest 5 company news on the homepage
Assuming the 'Company News' category ID is 10 and it belongs to the 'Article Model' (ID 1).
<div class="latest-news">
<h2>最新公司新闻</h2>
<ul>
{% archiveList news with moduleId="1" categoryId="10" limit="5" order="id desc" %}
{% for item in news %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
<span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</li>
{% empty %}
<li>暂无公司新闻。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Scenario two: Display popular recommended products in the sidebar.
Assuming the ID of the "product model" is 2 and the product is marked as "recommended" (c)
<div class="hot-products">
<h3>热门推荐产品</h3>
<ul>
{% archiveList hotProducts with moduleId="2" flag="c" limit="3" order="views desc" %}
{% for item in hotProducts %}
<li>
<a href="{{ item.Link }}">
<img src="{{ item.Thumb }}" alt="{{ item.Title }}">
{{ item.Title }}
</a>
</li>
{% empty %}
<li>暂无推荐产品。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Scenario three: Display the list of articles under the current category and its subcategories on the category page, and support pagination
Assuming the article model ID is 1 and in the template of the category page,archiveListit will automatically retrieve the current category ID.
<div class="category-articles">
<h1>{% categoryDetail with name="Title" %}</h1> {# 显示当前分类标题 #}
<ul>
{% archiveList articles with moduleId="1" type="page" limit="10" order="id desc" %}
{% for item in articles %}
<li>
<a href="{{ item.Link }}">{{ item.Title }}</a>
<span>所属分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
<span>阅读量:{{ item.Views }}</span>
</li>
{% empty %}
<li>当前分类下暂无文章。</li>
{% endfor %}
{% endarchiveList %}
</ul>
{# 分页导航 #}
{% pagination pages with show="5" %}
<div class="pagination-nav">
{% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
{% for item in pages.Pages %}
<a href="{{ item.Link }}" class="{% if item.IsCurrent %}active{% endif %}">{{ item.Name }}</a>
{% endfor %}
{% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
</div>
{% endpagination %}
</div>
By using these flexible parameter combinations,archiveListTags can help you build highly customized and powerful content lists to meet various display needs.
Frequently Asked Questions (FAQ)
1. How toarchiveListCan multiple filter conditions be applied in tags?
You can inarchiveListLabel parameters can be added directly, and the system will automatically combine these conditions to filter. For example, if you want to get the "article model" (moduleId="1") under the "Company News" category (categoryId="10") with the "Recommended" attribute (flag="c"Here is how you can write the latest 5 articles, {% archiveList news with moduleId="1" categoryId="10" flag="c" limit="5" order="id desc" %}.
2.archiveListWhich pages on the website can use the tags?
archiveListLabels can theoretically be used in any template file on the website (such as the homepage, category page, detail page, search results page, custom page, etc.). When you use it on a non-category page or non-model page, you may need to specify it more clearly.moduleIdorcategoryIdParameters such as this are not displayed on the category page or model page