Today, with the increasing refinement of content management, how to make the document list of a website flexible for different needs is a core skill that every website operator needs to master.The AnQiCMS (AnQiCMS) provides us with an extremely convenient and efficient solution with its powerful template tag system.This article will delve into how to accurately filter and display your document list in AnQiCMS based on various conditions such as categories, content models, and recommendation attributes.
core tools:archiveListtags
In AnQiCMS, we mainly use powerfularchiveListTemplate tags to control the display of the document list.This tag provides rich parameters, allowing you to combine various complex filtering conditions according to specific needs, just like building with Lego bricks.archiveListCan handle everything easily.
一、According to category filter document list
The website content is usually organized by different categories, such as "Company NewsarchiveListTagscategoryIdThe parameter is your preference.
- Specify a single category:You only need to assign the ID of the required category to
categoryIdthe parameter. For example,categoryId="1"Only documents under the category with ID 1 will be displayed. - Specify multiple categories:If you want to display documents from multiple categories in the same list, simply separate the category IDs with English commas, like
categoryId="1,2,3". - Include subcategories:AnQiCMS by default will intelligently display all documents of the current category and all its subcategories. If you want to focus only on the current category itself and exclude its subcategories, you can explicitly set
child="false". - Exclude specific categories:If you want to display all documents within a certain range but exclude one or two unrelated categories,
excludeCategoryIdthe parameter can come in handy, such asexcludeCategoryId="5".
Example code snippet:
{# 显示ID为1的分类下的最新10篇文章,包含子分类 #}
{% archiveList articles with categoryId="1" order="id desc" limit="10" %}
{% for item in articles %}
<li><a href="{{item.Link}}">{{item.Title}}</a></li>
{% endfor %}
{% endarchiveList %}
Second, filter document lists according to the content model
The flexible content model design of AnQi CMS allows you to easily manage articles, products, events, and other types of content.In some scenarios, you may want to display data from different content models on a single page.moduleIdThe parameters become particularly important.
- Specify a specific model:Each content model has a unique ID. For example, the article model may have ID 1, and the product model ID may be 2. You can get all articles by
moduleId="1"to get all articles, ormoduleId="2"Get all products.
Imagine that your website has both technical articles and product introductions, you might want to display them in different areas of the homepage.moduleIdIt can help you clearly distinguish between different types of content.
Example code snippet:
{# 显示所有产品模型下的最新5个产品 #}
{% archiveList products with moduleId="2" order="id desc" limit="5" %}
{% for item in products %}
<li>
<img src="{{item.Thumb}}" alt="{{item.Title}}">
<a href="{{item.Link}}">{{item.Title}}</a>
</li>
{% endfor %}
{% endarchiveList %}
3. Filter document list based on recommended attributes (Flag)
The Auto CMS provides a series of recommended attributes (Flag), allowing you to mark important content, such as "HeadlineThese tags can be easily set in the background when editing documents and are an excellent tool for enhancing content visibility and management flexibility.
- Specify recommended attribute:You can use
flagParameters can be used to filter documents with specific recommendation attributes. Common attribute values include:h: HeadlinescRecommendedf: Slidea: Recommendeds: Scrollp: Picturej: Jump You can use a single attribute, such asflag="c"Get all recommended content; it can also be combined, for example,flag="h,f"Get content that is both a headline and a slideshow.
- Exclude recommended attributes:Similarly, if you want to avoid certain properties' documents from appearing in the list,
excludeFlagthe parameter can help you exclude them.
Example code snippet:
{# 显示带有“幻灯(f)”属性的最新3篇文档 #}
{% archiveList slides with flag="f" order="id desc" limit="3" %}
{% for item in slides %}
<div class="carousel-item">
<img src="{{item.Logo}}" alt="{{item.Title}}">
<h3>{{item.Title}}</h3>
</div>
{% endfor %}
{% endarchiveList %}
4. Combination Filtering and Advanced Applications
These filtering conditions do not operate independently. You can combine them cleverly according to your actual needs to achieve a more refined display of document lists.
- Sorting method (
order):You can specify the sorting rules of the document, for example,order="views desc"(Sorted by views from high to low, i.e., popular documents),order="id desc"(Sorted by publication time from new to old, i.e., latest documents),order="sort desc"(Sorted by custom backend sorting). - Number of items displayed and pagination (
limitWithtype):limit="10": Used for fixed number of lists, such as displaying the latest 10 articles in the sidebar.)type="page"When you need to display documents in pagination, combinedpaginationwith tags, AnQiCMS will automatically handle the pagination logic, without the need for you to manually calculate the page numbers.
- search keywords (
q):When you need to display a list of documents containing specific keywords on the search results page, you can useq="搜索关键词"It is worth mentioning that when users submit keywords through the front-end search box, AnQiCMS will automatically capture the URL in theqparameter, and inarchiveListtags to take effect, achieving seamless search. - Related documents (
type="related"):In the document detail page, you can usetype="related"Automatically fetch other documents related to the current document, which helps to enhance user stay time. - Custom field filtering (
archiveFilters):In addition to the built-in properties, AnQiCMS also supports content filtering based on custom fields in the content model. This is usually associated witharchiveFiltersLabel配合使用,用于在前端页面生成用户可交互的筛选器(如下拉菜单、复选框),让用户能根据产品颜色、尺寸等自定义属性进行筛选。This provides the possibility of building a highly customized content filtering function.
An integrated example: Display popular articles with the "recommended" attribute under a certain category, and support pagination.
English
{% for item in popular_recommended_articles %}
<div class="article-card">
<img src="{{item.Thumb}}" alt="{{item.Title}}">
<h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
<p>{{item.Description}}</p>
<span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
<span>浏览量: {{item.Views}}</span>
</div>
{% empty %}
<p>当前分类下暂无推荐文章。</p>
{% endfor %}
{# 分页导航 #}
{% pagination pages with show="5"