Next, let's explore how to use the powerful template tags of Anqi CMS to achieve these refined content filtering and display.
Understanding the core:archiveListtags
The core tool used to retrieve content lists in AnQi CMS isarchiveList[en]Tags. It's 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 tag 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 habit.type="list"indicates that we want to get a simple list,limit="5"This limits the display to only the latest 5 pieces of content.
Filter content by category
The classification of website content is the most basic way to organize information.The Anqi CMS allows us to classify articles, products, and other content into different categories.categoryIdParameter.
Assume you have a category named 'Company News' with an ID of10. You can view the corresponding ID for each category on the 'Content Management' -> 'Document Categories' 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 there are subcategories under your classification and you want to display the content of all subcategories, by defaultarchiveListTags will be included. If you only want to display the contents of the current category without including subcategories, you can addchild=falseParameter.
Filter content based on the content model
One of the highlights of AnQi CMS is its flexible content model functionality. You can create 'article models', 'product models', even 'event models' to adapt to different business needs. Each content model has a uniquemoduleIdIn the 'Content Management' -> 'Content Model' page in the background, you can view these model IDs.
You can use it to display the latest product list on a single page, such as the homepage, instead of the article list.moduleIdto filter. Suppose the ID of the "product model" is2.
{# 显示产品模型(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"to ensure that the products released the latest are sorted.
Filter content according to recommended attributes (Flag)
The AnQi CMS allows you to set multiple recommended attributes for each document, such as "Top News", "Recommend", "Slider", etc. These attributes can be easily selected in the document editing interface in the backend, and each attribute has a corresponding single-letter identifier (such ashrepresents the headlinecrepresents recommendation,frepresents slide). Throughflagparameters, you can create various special display areas on the website.
For example, to display articles 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"The content marked as both "Headline" and "Recommended" will be displayed simultaneously.
Combine multiple filtering conditions.
The strength of AnQi CMS lies in the flexibility to combine the above filtering conditions to achieve more accurate content location. For example, you may want to filter by the "Technical Articles" category (categoryId="12"Below, filter out the popular technical articles that belong to the "Article Model" (moduleId="1") and are marked as "Recommended (c)".
{# 组合筛选:显示技术文章分类下,文章模型中,被推荐的内容,并按浏览量倒序排列 #}
{% 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 classification, model, and recommendation attributes, but alsoorder="views desc"prioritize the most popular articles for display, andlimit="4"controlled the number of displayed items.
Advanced Filtering: Exclude Specific Content and Custom Fields
In addition to the basic filtering,archiveListwe also provide some advanced options, such asexcludeCategoryIdandexcludeFlag, which can exclude the content of specific categories or recommended attributes.
When you define custom fields (such as "article source") in your website's content model and want to perform more dynamic filtering based on these fields, you may consider usingarchiveFiltersTags, it will generate filter links based on the custom fields you set in the backend,配合archiveListofqFilter content by parameter or URL query parameter.This is typically used to build more complex filtering pages, such as real estate websites filtering listings based on apartment layout and area.