When using Anq CMS to manage website content, we often need to display specific content (such as articles, products) in the form of a list in different areas of the website.This means that we may need to display the latest headline articles on the homepage, only show products from a specific series on the product category page, or recommend some popular content in the sidebar.AnQi CMS provides flexible tags, allowing us to accurately filter and display the desired content list based on various conditions such as categories, content models, or recommended attributes.
Next, let's explore how to use the powerful template tags of Anqi CMS to achieve these refined content filtering and display.
Understand the Core:archiveListTag
The core tool used to retrieve content lists in AnQi CMS isarchiveListLabel. It is like a universal content filter, which can meet the vast majority of content display needs through the combination of different parameters.
The basic structure of this label is usually like this:
{% archiveList articles with type="list" limit="5" %}
{% for article in articles %}
{# 在这里展示每一篇文章的详细信息,比如标题、链接、缩略图等 #}
<div class="article-item">
<a href="{{ article.Link }}">{{ article.Title }}</a>
{% if article.Thumb %}
<img src="{{ article.Thumb }}" alt="{{ article.Title }}">
{% endif %}
<p>{{ article.Description }}</p>
</div>
{% endfor %}
{% endarchiveList %}
In the above example,articlesThis is the variable name defined for the list of content obtained, you can name it according to your own habits.type="list"It means we want to get a simple list, andlimit="5"It limits the display to only the latest 5 items.
Filter content by category
The classification of website content is the most basic way to organize information. Anqi CMS allows us to classify articles, products, and other content into different categories.We need to usecategoryIdParameter.
Assuming you have a category named "Company News" with ID10. You can view the corresponding ID for each category on the "Content Management" -> "Document Category" page.
To display all articles under the "Company News" category, you can write the code like this:
{# 显示分类ID为10(例如“公司新闻”)下的内容 #}
{% archiveList newsList with categoryId="10" type="list" limit="8" %}
<h3>最新公司新闻</h3>
{% for news in newsList %}
<div class="news-item">
<a href="{{ news.Link }}">{{ news.Title }}</a>
<span>发布日期: {{ stampToDate(news.CreatedTime, "2006-01-02") }}</span>
</div>
{% else %}
<p>暂时没有公司新闻。</p>
{% endfor %}
{% endarchiveList %}
If your category has subcategories and you want to display the content of all subcategories by defaultarchiveListThe label will include. If you only want to display the content of the current category without including subcategories, you can addchild=falseParameter.
Filter content based on the content model
A key feature of AnQi CMS is its flexible content model function, you can create 'article models', 'product models', even 'event models' to meet different business needs. Each content model has a uniquemoduleId. On the "Content Management" -> "Content Model" page in the background, you can view the IDs of these models.
If you want to display the latest product list on a page, such as the homepage, instead of the article list, you can usemoduleIdto filter. Assuming the ID of the2.
{# 显示产品模型(moduleId="2")下的最新产品 #}
{% archiveList productList with moduleId="2" order="id desc" type="list" limit="6" %}
<h2>热门产品推荐</h2>
<div class="product-grid">
{% for product in productList %}
<div class="product-card">
<a href="{{ product.Link }}">
<img src="{{ product.Thumb }}" alt="{{ product.Title }}">
<h4>{{ product.Title }}</h4>
</a>
</div>
{% endfor %}
</div>
{% endarchiveList %}
Here we also usedorder="id desc"Make sure to sort products by the latest release.
Filter content based on recommended attributes (Flag)
The Anqi CMS allows you to set various recommended properties for each document, such as "headline", "recommended", "slide" etc. These properties can be easily selected in the document editing interface in the background, and each property has a corresponding single-letter identifier (such ashrepresenting the headline,cRepresents recommendation,fRepresents slide).Pass through,flagParameter,you can create various special display areas on the website.
For example, to display the article marked as "slide (f)" in the carousel position on the homepage:
{# 显示被标记为“幻灯(f)”的内容作为轮播图 #}
{% archiveList sliderItems with flag="f" type="list" limit="5" %}
<div class="main-slider">
{% for item in sliderItems %}
<div class="slider-item">
<a href="{{ item.Link }}">
<img src="{{ item.Logo }}" alt="{{ item.Title }}">
<h3>{{ item.Title }}</h3>
</a>
</div>
{% endfor %}
</div>
{% endarchiveList %}
You can also combine multipleflagValues, separated by commas, for exampleflag="h,c"Content marked as both 'Headline' and 'Recommended' will be displayed at the same time.
Combine multiple filtering conditions.
The strength of AnQi CMS lies in the flexibility to combine the above filtering conditions to achieve more precise content location. For example, you may want to filter in the "Technical Articles" category (categoryId="12") under, filter out the ones belonging to the "article model" (moduleId="1") and marked as "recommended (c)" popular technical articles.
{# 组合筛选:显示技术文章分类下,文章模型中,被推荐的内容,并按浏览量倒序排列 #}
{% archiveList featuredTechArticles with categoryId="12" moduleId="1" flag="c" order="views desc" type="list" limit="4" %}
<h2>精选技术推荐</h2>
<ul class="featured-list">
{% for article in featuredTechArticles %}
<li>
<a href="{{ article.Link }}">{{ article.Title }}</a>
<span>({{ article.Views }} 阅读)</span>
</li>
{% endfor %}
</ul>
{% endarchiveList %}
In this example, we not only combined categories, models, and recommendation attributes, but also throughorder="views desc"Made the most popular articles appear first, and usedlimit="4"Controlled the number of displayed items.
Advanced filtering: Exclude specific content and custom fields
In addition to basic filtering,archiveListit also provides some advanced options, such asexcludeCategoryIdandexcludeFlag, which can exclude specific categories or recommended attribute content.
When you define custom fields (such as "article source") in your website's content model and want to use them for more dynamic filtering, you can consider usingarchiveFiltersThe label, it will generate a filter link based on the custom fields set in your background,配合archiveListofqParameters or URL query parameters are used to filter content. This is usually used to build more complex filtering pages, such as real estate websites filtering listings based on apartment type, area, and other factors.However, the specific implementation involves passing and processing URL parameters, and is more suitable for users with template development experience