As an expert who has been deeply involved in the CMS content operation field for a long time, I fully understand the importance of a flexible and efficient template tag for website content display. Among them, archiveListThe tag is undoubtedly the core tool for calling the document list in Anqi CMS templates.It can not only help us accurately filter and display various document content, but also combine multiple parameters to meet the ever-changing content presentation needs, thus providing readers with a high-quality browsing experience.
archiveListThe purpose and basic structure of the label
archiveListLabels in the Aanqi CMS are used to retrieve document lists. Whether it is a regular document list, a related document list, or a document list with pagination features, it can handle it. Its basic usage involves defining a variable to store the retrieved document data, and配合forLoop through these data.
a typicalarchiveListThe tag structure is as follows:
{% archiveList archives with type="list" limit="10" %}
{% for item in archives %}
{# 在这里展示文档内容 #}
<h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
<p>{{item.Description}}</p>
<p>发布时间: {{stampToDate(item.CreatedTime, "2006-01-02")}}</p>
{% empty %}
<p>抱歉,没有找到任何文档。</p>
{% endfor %}
{% endarchiveList %}
In this example,archivesIs the variable name we define, used to storearchiveListThe collection of documents obtained.{% for item in archives %}To loop through this collection,itemthen it represents each document object in the collection. When there is no document data,{% empty %}the content of the region will be displayed.
Precise control:archiveListParameter Details
archiveListThe power of the tag lies in its rich parameters, through which we can make fine-grained filtering and sorting of the document list.
Model ID (moduleId)
This parameter is used to specify which content model's document list should be retrieved. For example, if you want to retrieve the document list under the 'Article Model', you can setmoduleId="1"If you want to get the documents under the "Product Model", it may be set asmoduleId="2". In the content management of the Anqi CMS backend, each content model has its corresponding ID.
Category ID (categoryId)
categoryIdParameters allow you to retrieve the document list under a specified category. You can pass a single category ID, such ascategoryId="5", or multiple category IDs, separated by commas, such ascategoryId="1,2,3"If this parameter is not specified,archiveListTry to read the category ID of the current page. If you want to call the document on a non-category page but do not want to automatically read the current category, or explicitly do not want to filter by the current category, you can explicitly setcategoryId="0".
Exclude category ID (excludeCategoryId)
WithcategoryIdOn the contrary,excludeCategoryIdUsed to exclude documents under a specific category. This is very useful when you want to display most of the documents but want to skip certain specific categories, for exampleexcludeCategoryId="10"Exclude all documents under the category with ID 10.
User ID (userId)
If you need to display documents published by a specific user, you can useuserIdparameters. For example,userId="1"This will only display documents published by users with ID 1.
Parent document ID (parentId)
This parameter is used to get the child documents of the specified parent document. If your content structure has a hierarchical relationship (such as the attachment list under the product detail page),parentId="某个文档ID"it can be very useful.
Recommended properties (flag)
Auto CMS allows setting various recommended attributes for documents, such as "HeadlineflagParameters can help you filter documents based on these attributes, for exampleflag="c"Only documents marked as “Recommended” will be displayed. Multiple attribute values can be set by combining letters.
Exclude recommended attributes (excludeFlag)
This parameter is used to exclude documents with specific recommendation properties, such asexcludeFlag="s"Documents marked as 'scroll' will not be displayed.
Whether to list the documents offlag(showFlag)
When you want to display the recommended attribute tags of each document directly in the document list, you need to setshowFlagsettrueThe default value isfalse.
Whether to display the content of subcategories (child)
By default, when you specifycategoryIdwhenarchiveListIt will include the category and all documents under its subcategories (child=true). If you only want to display the documents of the specified category itself and not include the documents under its subcategories, you can setchild=false.
Sort method (order)
orderThe parameter determines the display order of the document. Common sorting methods include:
- Sort by the most recent release:
order="id desc" - Sort by the most views:
order="views desc" - Sort by custom sorting in background:
order="sort desc"(This is the default sorting method and can be left blank)
Display Quantity (limit)
limitThe parameter is used to control the number of documents returned. For example,limit="10"only 10 documents will be displayed. When you do not need pagination functionality,limitIt also supportsoffsetMode, for examplelimit="2,10"This indicates starting from the second document and fetching 10 data items.
List type (type)
this is a very critical parameter, which determinesarchiveListLabel behavior pattern:
type="list"(Default): Display documents in a normal list format, affected bylimitparameter control, no pagination provided.type="page":用于带有分页功能的文档列表。当使用此类型时,通常需要结合paginationtags to generate pagination navigation.type="related":用于获取相关文档。在这种模式下,archiveListIt will try to retrieve other documents most relevant to the current document. It can also refine the relevance judgment by combininglikeparameters further, for examplelike="keywords"(by keyword relevance) orlike="relation"(Manual settings according to the relevant documents in the background).
Search keywords (q)
Whentype="page"whenqThe parameter can be used to specify the search keywords. If you include them in the URL,q=关键词Query parameters,archiveListIt will automatically read and use it for searching documents with the specified keyword in the title. You can also specify it directly in the tag.q="您的关键词".
Filter parameters (custom)
Intype="page"模式下,If your content model is configured with filterable custom fields (such as “House Type”, “Price Range”), you can pass these fields as query parameters in the URL,archiveListIt will perform advanced filtering based on these parameters. For example, if the custom field issexwith the value男, you can filter through URL query parameterssex=男.
Site ID (siteId)
When you use the multi-site management feature of AnQi CMS, if you need to call data from other sites, you can do so bysiteIdspecifying the target site's ID as a parameter.
combining the document ID (combineId) And combination document ID (combineFromId)
These are advanced parameters used to create a combined comparison page for documents.For example, if you want to compare two products A and B, you can take product A as the main document and product B as the composite document.combineIdA combination ID will be added to the main document URL, for example/tour/1/c-2.htmlwhere,1Is the main document ID2Is the combination document ID.combineFromIdSimilar, but the combined document comes first, for example/tour/2/c-1.html.forIn the loop, you can{{combine.文档字段}}or{{combineArchive.文档字段}}to access the information of the combined document.
forDocument fields available in the loop
InarchiveListofforin the loop,itemThe variable represents each document object, it contains a series of fields that can be directly accessed, making it convenient for you to display in templates. Here are some commonly used fields:
{{item.Id}}: The unique ID of the document.{{item.Title}}: Document Title.{{item.Link}}: Document detail page URL.{{item.Description}}: Document summary or abstract.{{item.Keywords}}: Document keywords.{{item.CategoryId}}The ID of the category the document belongs to.{{item.Views}}: Document views.{{item.Logo}}: Document cover first image URL (large image).{{item.Thumb}}: English document cover thumbnail URL.{{item.Images}}: Array of multiple document cover images, which needs to be traversed with nested loops.{{item.CreatedTime}}: English document creation time (Unix timestamp), usually combined withstampToDateEnglish filter formatting.{{item.UpdatedTime}}: English document update time (Unix timestamp).{{item.Flag}}: 文档的推荐属性标记。{{item.CommentCount}}: Document comment count.- 文档模型自定义字段: 如果您在后台为文档模型定义了额外的自定义字段,例如
authororprice,它们也可以通过{{item.自定义字段名}}of the form directly access.
Application scenarios and code examples
Let us demonstrate through several specific scenarios.archiveListThe powerful functions of the tag.
Scenario one: Display the latest 10 articles released.
On the homepage or sidebar of the website, we often need to display the latest published content.
<div class="latest-articles">
<h2>最新文章</h2>
<ul>
{% archiveList latestArchives with moduleId="1" order="id desc" type="list" limit="10" %}
{% for article in latestArchives %}
<li>
<a href="{{article.Link}}" title="{{article.Title}}">
<img src="{{article.Thumb}}" alt="{{article.Title}}" onerror="this.style.display='none';">
<span class="title">{{article.Title}}</span>
<span class="date">{{stampToDate(article.CreatedTime, "2006-01-02")}}</span>
</a>
</li>
{% empty %}
<li>暂无最新文章。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
In this example,moduleId="1"The article model is specified,order="id desc"Ensure that it is sorted by the latest published,type="list"andlimit="10"Then it controls the list format and quantity.
Scenario two: article list page with pagination
On a category list page, it is usually necessary to display all articles under the category and provide pagination navigation.
<div class="category-articles">
<h1>{{category.Title}}</h1> {# 假设当前页面是分类页,category变量已存在 #}
<div class="article-list">
{% archiveList articles with type="page" limit="15" %} {# 默认会获取当前分类的文档 #}
{% for article in articles %}
<div class="article-item">
<h2><a href="{{article.Link}}">{{article.Title}}</a></h2>
<p class="meta">
<span>发布于: {{stampToDate(article.CreatedTime, "2006-01-02")}}</span>
<span>分类: <a href="{% categoryDetail with name='Link' id=article.CategoryId %}">{% categoryDetail with name='Title' id=article.CategoryId %}</a></span>
<span>浏览量: {{article.Views}}</span>
</p>
<div class="description">{{article.Description}}</div>
<a href="{{article.Link}}" class="read-more">阅读更多</a>
</div>
{% empty %}
<p>该分类下暂无文章。</p>
{% endfor %}
{% endarchiveList %}
</div>
<div class="pagination-nav">
{% pagination pages with show="7" %}
<ul>
{% if pages.PrevPage %}
<li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
{% endif %}
{% for p in pages.Pages %}
<li {% if p.IsCurrent %}class="active"{% endif %}><a href="{{p.Link}}">{{p.Name}}</a></li>
{% endfor %}
{% if pages.NextPage %}
<li><a href="{{pages.NextPage.Link}}">下一页</a></li>
{% endif %}
</ul>
{% endpagination %}
</div>
</div>
Here we usedtype="page"andlimit="15"To implement pagination and combine it.paginationTags have generated pagination links.categoryDetailTags are used to obtain detailed information about the category of the article.
Scenario three: Display related products on the product detail page.
To enhance user experience and site traffic, we can display related products at the bottom of the product details page related to the current product.
<div class="related-products">
<h3>相关产品推荐</h3>
<ul>
{% archiveList relatedProducts with type="related" like="keywords" limit="5" %}
{% for product in relatedProducts %}
<li>
<a href="{{product.Link}}" title="{{product.Title}}">
<img src="{{product.Thumb}}" alt="{{product.Title}}">
<span class="title">{{product.Title}}</span>
</a>
</li>
{% empty %}
<li>暂无相关产品。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
type="related"mode,archiveListwill intelligently search for related documents. Herelike="keywords"Further indicate the system to match relevance based on keywords