Today, with the increasing refinement of content management, how to make the document list of a website flexible to display according to different needs is a core skill that every website operator needs to master.AnQiCMS (AnQiCMS) takes advantage of its powerful template tag system, providing us with an extremely convenient and efficient solution.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, recommendation attributes, and more.
Core tool:archiveListTag
In AnQiCMS, we mainly use powerfularchiveListThe template tag controls the display of the document list. This tag provides rich parameters, allowing you to build various complex filtering conditions like building Lego blocks according to specific needs.Whether it is to display the latest articles, hot products, or content on specific themes,archiveListCan easily handle.
One, filter document list by category
Website content is usually organized into different categories, such as "Company News", "Industry Dynamics", "Product Cases", and so on. When you want to display documents under a specific category on the page, archiveListlabel'scategoryIdThe parameter is your preference.
- Specify a single category:You just 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, just separate the category IDs with English commas, for example:
categoryId="1,2,3". - Include subcategories:AnQiCMS is default to intelligently display the 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 a specific category:If you want to display all documents within a certain range but exclude one or two unrelated categories,
excludeCategoryIdthe parameter can be used, 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 the document list according to the content model
Flexible content model design of Anqi CMS, allowing you to easily manage articles, products, events, and other types of content.In certain scenarios, you may want to display data from different content models on a single page. At this point,moduleIdParameters are particularly important.
- Specify a particular model:Each content model has a unique ID. For example, the article model may have an ID of 1, and the product model may have an ID of 2. You can
moduleId="1"to get all articles, ormoduleId="2"Get all products.
Imagine, your website has both technical articles and product introductions, you may want to display them in different areas of the homepage.moduleIdIt can help you clearly separate 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 according to recommended attributes (Flag)
AnQi CMS provides a series of recommended attributes (Flag) that allow you to mark important content, such as "Headline", "Recommended", "Slideshow", and so on.These 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 attributes:You can use it to
flagParameters to filter documents with specific recommendation attributes. Common attribute values include:h: Headlinesc: Recommendationsf: Slidesa: Special Recommendationss: Scrollp: Imagej: Go to You can use a single attribute, such asflag="c"to get all recommended content; you can also combine them, such asflag="h,f"to get content that is both headlines and slides.
- Exclude recommended properties:Similarly, if you want to avoid certain specific properties from appearing in the list,
excludeFlagthe parameter can help you exclude.
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 document list display.
- Sorting method (
order):You can specify the document sorting rules, for exampleorder="views desc"Sorted by view count from high to low, i.e., popular documents,order="id desc"Sorted by publication time from new to old, i.e., the latest documents,order="sort desc"(Sorted by custom sorting in the background). - Display number and pagination(
limitwithtype):limit="10": Used for a fixed number of lists, such as displaying the latest 10 articles in the sidebar.type="page": When you need to display documents with pagination, combine withpaginationUse tags, AnQiCMS will automatically handle pagination logic, there is no need to manually calculate 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 a user submits a keyword through the front-end search box, AnQiCMS will automatically capture the parameter in the URLqand it will take effect in thearchiveListtag to achieve seamless search. - Related documents (
type="related"):On the document details page, you can usetype="related"To automatically retrieve other documents related to the current document, which helps to increase 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 witharchiveFiltersUsed in conjunction with labels, it is used to generate user-interactive filters on the front-end page (such as drop-down menus, checkboxes), allowing users to filter based on product properties such as color, size, etc.This provides the possibility for you to build a highly customized content filtering function.
A comprehensive example: displaying popular articles under a certain category with the 'recommended' attribute and supporting pagination.
”`twig {# Assuming the current page is a category list page, categoryId will be automatically retrieved #} {% archiveList popular_recommended_articles with type=“page” flag=“c” order=“views desc” limit=“10” %}
{% 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"