In the 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 your website. Whether it's displaying the latest articles under a specific category, popular products under a certain content model, or thematic documents with specific recommendation properties, archiveListCan be achieved through its rich parameter configuration to accurately meet these needs.
Accurately locate content: categories, models, and recommendation attributes
First, let's understandarchiveListTags are the most commonly used dimensions for filtering content: categories, content models, and recommendation properties.
1. Filter documents by category (categoryId)
The content of a website is usually categorized under different categories based on its theme, such as 'Company News', 'Industry Dynamics', or 'Product Introduction', etc.archiveListTags can be used tocategoryIdParameters, allowing you to easily specify which category or categories of documents to display.
- Specify a single or multiple categoriesIf you want to display documents under a specific category (e.g., ID 10), you can use it like this:
{% archiveList archives with categoryId="10" %}If you need to display documents under multiple categories (e.g., IDs 10, 12, 15), just separate them with commas:{% archiveList archives with categoryId="10,12,15" %}. - Control the content of subcategoriesIn some cases, you may only want to display 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 subcategory content. If you only want the documents of the current category (ID is 10), you can write it like this:{% archiveList archives with categoryId="10" child="false" %}. - It does not depend on the current page category[en] Sometimes, even when you are on the category page, you may not want to
archiveListautomatically read the category ID of the current page. In this case, you can explicitly setcategoryId="0"To prevent this automatic behavior and specify the categories ID that need to be filtered.
2. Filter documents by content model (moduleId)
One of the highlights 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.).archiveListTagged throughmoduleIdParameters, allowing you to accurately filter out documents belonging to a specific content model.
- Identify content modelIn the AnQi CMS backend, you can create content models for different content types (such as the system default 'Article Model' and 'Product Model').Each content model has a unique ID.
archiveListIt can only display the documents under the model. For example, if you want to display the documents under the product model with ID 2, you can use it like this:{% archiveList products with moduleId="2" %}. - Combine categories with modelsYou can also use:“
moduleIdandcategoryIdCombined with, for example, displaying a list of products under a certain category that belong to a product model.
3. Filter documents by recommended attributes (flag)
When publishing documents, the Safe CMS provides various recommended attributes such as "Headlines", "Recommendations", "Sliders", etc., which are identified by different letters (for example, hrepresents the headlinecRepresent recommended).archiveListTags can be used toflagParameters, filter content based on these properties.
- Specify recommended 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 attributes, for exampleflag="h,c"Documents that are both headlines and recommended will be displayed. - Exclude specific attributes: To exclude documents with certain specific attributes, you can use
excludeFlagparameters. For example,{% archiveList normalDocs with excludeFlag="h" %}It will display all non-headline documents. - Show attribute identifier: If you need to display the recommended attributes of documents in the list, you can
archiveListtag.showFlag="true"Parameter.
Extended filtering capabilities: More practical parameters
In addition to the above core filtering criteria,archiveListwe also provide various other parameters to further optimize your content list:
- Sort method (
order)You can sort documents by document ID (latest release), views (most popular), or custom sorting on the backend. For example,order="id desc"indicates sorting by ID in descending order (latest release),order="views desc"Represents sorting by view count in descending order. - Show quantity and pagination (
limit,type="page"):limitParameter used to control how many documents are displayed. If you need to implement pagination functionality, you can use thetypeparameter settings"page"and combine.paginationtag to create a complete pagination navigation. - Search keywords (
q)In the search results page, :qparameters can be used to match content that includes specific keywords in the document title. If the URL already containsqparameters,archiveListit will be automatically read and applied. - Custom filter parametersThe [en] security CMS allows you to define custom fields for content models in the backend. If these fields are set to be filterable,
archiveListYou can further filter based on query parameters in the URL, which is very useful for creating highly customized filtering interfaces (such as property websites filtering by area and layout). You can combinearchiveFiltersBuild these filtering conditions with tags. - Multi-site data call (
siteId): If you use the multi-site management feature of Anqi CMS,siteIdparameters allow you to call data from other sites. - Combined document display (
combineId,combineFromId)This is an advanced usage to combine multiple documents for display in a list, such as showing a 'tour route from Location A to Location B'. It can dynamically combine document titles and links, commonly used in scenarios for comparison or combination of information.
Example of practical application scenarios
Let's look at several common scenarios to seearchiveListhow tags play a role:
Scenario one: Display the latest 5 company news on the homepage
Assuming that the ID of the 'Company News' category 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: Displaying popular recommended products in the sidebar.
Assuming the 'product model' ID 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 obtain 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>
Through these flexible parameter combinations,archiveListTags can help you build highly customized and powerful content lists, meeting various content display needs.
Common Questions (FAQ)
1. How toarchiveListapply multiple filtering conditions at the same time in tags?
You can do this onarchiveListTags can directly add multiple parameters at the same time, and the system will automatically combine these conditions for filtering. For example, if you want to get the "Article Model" (moduleId="1"Under the "Company News" category,categoryId="10"which also have the "Recommended" attribute,flag="c"The latest 5 articles can be written as follows:{% archiveList news with moduleId="1" categoryId="10" flag="c" limit="5" order="id desc" %}.
2.archiveListWhere can the tags be used on the website pages?
archiveListTags can theoretically be used in any template file of the website (such as the homepage, category page, detail page, search results page, custom page, etc.). When you use it on non-category pages or non-model pages, you may need to specify it more explicitly.moduleIdorcategoryIdParameters. But on the classification page or model page