AutoCMS is an efficient enterprise-level content management system. Its powerful content tags are the core of dynamic and personalized content display. For website operators, being proficient in using these tags, especiallyarchiveListThis can greatly enhance the flexibility and efficiency of content management.
This article will detail how to usearchiveListTags, precisely call the document list of specified categories and recommended attributes, helping you to better build website pages that meet user needs and optimize content display.
archiveList标签:Dynamic content display core
In the Anqi CMS,archiveListLabels are the key tools used to retrieve and display document lists from the database. Whether it's articles, products, or other custom content models, as long as you want to present them in a list format,archiveListIt can be used in various situations. It provides rich parameters to allow you to finely control the filtering, sorting, and quantity of content, thereby achieving highly customized page layouts.
Filter documents of specified categories
When building a website, we often need to display documents under specific categories on a single page.For example, display all news articles on the "News Center" page or show a specific model of product on the "Products" page.archiveListTagged throughcategoryIdParameters, can easily achieve this requirement.
You can by settingcategoryIdParameter assignment, to specify the category ID that needs to be called. If your category ID is1, the format iscategoryId="1"If you need to display documents from multiple categories at the same time, you can separate multiple category IDs with commas, for examplecategoryId="1,2,3".
In some cases, you may wish toarchiveListAutomatically identify the category of the current page and display the documents under this category. In this case, it is usually possible to omit.categoryIdParameters, the system will automatically try to retrieve the current page's category ID. However, if you want to explicitly not automatically retrieve the current category ID, or to call documents for all categories on a non-category page (such as the homepage), you can setcategoryId="0"To avoid the system automatically reading.
Also,archiveListIt also provideschildparameters to control whether to include documents of subcategories. By default,childparameter astrueThis means that when calling the parent category, all documents under its child categories will also be included in the list. If you only want to display the documents of the current category itself and do not want to involve any child categories,childsetfalse.
Call documents with recommended attributes
The document publishing feature of AnQi CMS allows content creators to set various recommended attributes for documents, such as headlines, recommendations, slides, etc.These properties are crucial in website content operation, which can be used to highlight important content, such as the homepage featured images, sidebar recommended articles, etc.archiveListTagged throughflagParameters, allowing you to filter documents based on these recommended attributes.
The system provides the following recommended attributes:
- Top News
h - [en] Recommended
c - Slide
f - [en]Special Recommendation
a - Scrolling
s - Bold
h(Note, this repeats the letters of the attribute headlines, and the specific usage should refer to the internal processing logic or model document of the system. However, usually, a Flag letter represents an independent attribute) - Image
p - Jump
j
To call documents with specific recommendation properties, you just need to assign the corresponding attribute letters toflagparameters. For example, to display all documents marked as “recommended”, you can set it like this:flag="c". If you want to display the 'slider' content on the homepage, you can useflag="f"[en] It should be noted that,flag参数一次只能指定一个属性值进行筛选。如果您的网站在后台配置了多个推荐属性,您可以根据实际需求,创建多个archiveListCall, each call filters a specific property.
Comprehensive application and code examples
In practical applications, we often need to combine classification and recommendation attributes to accurately locate content.For example, on a category page sidebar, you may want to display a list of 'recommended' articles under that category.
{# 示例:在一个文章模型分类页面,显示当前分类下的“推荐”文章,限制显示5条 #}
{# archives 是您定义的变量名称,用于接收文档列表数据 #}
{% archiveList archives with type="list" categoryId="0" flag="c" limit="5" order="id desc" %}
{% for item in archives %}
<li>
<a href="{{ item.Link }}" title="{{ item.Title }}">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}">
{% endif %}
<h3>{{ item.Title }}</h3>
<p>{{ item.Description|truncatechars:80 }}</p>
<span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</a>
</li>
{% empty %}
<li>当前分类下暂无推荐文章。</li>
{% endfor %}
{% endarchiveList %}
In the above example:
type="list"Represents that we want to get a simple list, not a paginated list.categoryId="0"Enables the label to automatically retrieve the current page's category ID (if on a category page) or not restrict categories (if on the homepage, etc.). If you know the exact category ID, you can directly replace it withcategoryId="具体分类ID".flag="c"Specify explicitly to retrieve documents marked as “Recommended”.limit="5"Limited the list to display the latest 5 articles.order="id desc"Then the documents are sorted in descending order by document ID, usually meaning the most recently released documents are at the top.
If your requirement is to display all the 'Top News' documents under all models and need to be paginated, you can write it like this:
{# 示例:显示所有内容模型下的“头条”文档,并进行分页 #}
{# archives 变量用于文档列表数据 #}
{% archiveList archives with type="page" flag="h" limit="10" order="views desc" %}
{% for item in archives %}
<div class="archive-item">
<h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
<p>{{ item.Description }}</p>
<span>浏览量:{{ item.Views }}</span>
<span>更新时间:{{ stampToDate(item.UpdatedTime, "2006-01-02 15:04") }}</span>
</div>
{% empty %}
<p>暂无头条文档。</p>
{% endfor %}
{# pages 变量用于分页信息 #}
{% pagination pages with show="5" %}
<div class="pagination-controls">
{% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
{% for page_item in pages.Pages %}
<a href="{{ page_item.Link }}" class="{% if page_item.IsCurrent %}active{% endif %}">{{ page_item.Name }}</a>
{% endfor %}
{% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
</div>
{% endpagination %}
{% endarchiveList %}
In this example:
type="page"It indicates that the pagination feature is enabled.flag="h"Filter out all 'Top News' documents.limit="10"Set the number of documents displayed per page to 10.order="views desc"Sort documents by views in descending order.- Combined with
paginationUse tags to generate pagination links for easy browsing.
Summary
archiveListLabels are an indispensable tool in the development of AnQi CMS templates. By flexibly utilizingcategoryIdandflagthese two core parameters, combined withtype/limit/orderWith other parameters, you can easily achieve various complex document list display requirements.This not only improves the organization efficiency of website content, but also provides users with a more personalized and convenient browsing experience.
Frequently Asked Questions
how to be in aarchiveListAre documents being filtered out simultaneously while calling that have multiple recommended attributes (such as being both "Headline" and "Recommended")?
archiveListTagsflagThe parameter is designed to accept only one recommended attribute for filtering at a time. This means you cannot directly filter in the samearchiveListlabel by tag.flag="h,c"The way to filter multiple attributes at the same time. If you need to display documents that meet multiple recommendation attributes simultaneously, it usually requires implementing custom program logic, such as adding a composite attribute in the background, or performing multiple operations.archiveListCall and merge processing on the front-end (this is usually not recommended as it increases rendering complexity).The better approach is to ensure that the recommended attributes of the backend can meet your single filtering needs, or design more detailed categories to differentiate content.
My document list has already set the recommendation attribute, but why does the flag mark not display on the front page?
archiveListTags are not included by default in the returned document dataFlagProperties detail information. If you want to get the recommended properties of each document in the loop (for example,for), you need to explicitly set the parameters in the tag.{{item.Flag}}), you need to explicitly set the parameters in the tag.archiveList, you need to explicitly set the parameters in the tag.showFlag=trueAfter setting, item.FlagThis will return the alphabetical combination of all recommended properties of the document, for example,hcIt means both头条 and recommended.
If I only want to display documents under the current category on the article list page, excluding any documents from subcategories, how should I set it up?archiveListTags?
archiveListTagschildParameter controls whether to include documents of subcategories. By default,childhas a value oftrueThis means that when you filter a category, all subcategories' documents will also be included in the list. If you want to strictly limit the display to only the current category (i.e., the parent category itself) and not include any documents from its subcategories, you should setchildparameter settingsfalse, for example:{% archiveList archives with categoryId="当前分类ID" child=false limit="10" %}.