As a senior security CMS website operator, I am well aware of the key role of efficient content management and accurate content presentation in the success of a website.In AnQiCMS, flexibly using template tags is an important way to achieve this goal.Today, we will delve into how to utilizearchiveListTemplate tag, retrieves and displays document lists based on specified conditions to meet the diverse content display needs.
MasterarchiveListLabel: The powerful foundation of content display.
In AnQiCMS template development,archiveListTags are the core tools for retrieving document lists. Whether you need to display the latest articles, popular products, content under specific categories, or even implement complex filtering and search results,archiveListCan provide strong support. It can extract document data that meets the conditions you set from the database, and display it in a loop on the front-end template.
archiveListThe basic syntax structure of tags is concise and clear, usually with{% archiveList 变量名称 with 参数 %}...{% endarchiveList %}The form appears. Wherein, "variable name" is a variable you define to carry the collection of document data received in a loop;withAfter the keyword, you can add a series of parameters to accurately control document filtering and sorting.
Core parameter details: Precisely control document acquisition
To give full play toarchiveListThe power, understanding its various parameters is crucial. The following are some of the core parameters you will use in the applicationarchiveListSome of the most commonly used core parameters when using
moduleId(Model ID)This parameter allows you to specify which content model to retrieve documents from. For example,moduleId="1"It is usually used to retrieve documents from the article model, andmoduleId="2"Documents that may be used to obtain product models. Accurately specifying the model ID can prevent data confusion across models and ensure professionalism.categoryId(Category ID)BycategoryIdYou can specify to retrieve documents under a specific category. For example,categoryId="1"Get all documents under the category with ID 1. If you need to get documents from multiple categories, you can use commas to separate multiple IDs, likecategoryId="1,2,3"It is worth noting that if this parameter is not specified,archiveListit will attempt to automatically read the category ID of the current page. If you wish to completely disable this automatic behavior, you can explicitly setcategoryId="0".excludeCategoryId(Exclude Category ID)withcategoryIdOn the contrary,excludeCategoryIdUsed to exclude documents under a specific category. This is very useful when you need to display all content except for certain categories.userId(Author ID)You can use to display documents published by a specific authoruserIdparameters, for exampleuserId="1"The documents published by the author with user ID 1 will be obtainedparentId(Parent document ID)This parameter is very useful when there is a hierarchical relationship between documents. For example, you may need to get all the "child documents" under a certain "parent document".flag(Recommended attribute)AnQiCMS provides various recommended attributes for documents, such as headlines [h], recommendations [c], slides [f], and so on. Throughflag="c"You can easily filter out documents with the "recommended" attribute, which is very helpful for displaying recommended content on the homepage or column page.excludeFlag(Exclude recommended attribute)withflagsimilar,excludeFlagAllow you to exclude documents with specific recommendation attributes, such as not displaying "top news" content in a certain area.showFlag(Whether to display the document's flag)By default, the recommended properties of the document (Flagfield) are not visible in list items. If you need to display these properties on the front end, for example with icons or text marks, you must setshowFlagis set totrue.child(Whether to display subcategory content)When you get the documents of a category,childParameters (default totrue)Determine whether to include documents under its subcategories. If you only want to display documents of the current category itself and not include its subcategories, please setchild=false.order(Sorting method)The sorting method of documents is crucial.orderParameters support multiple sorting rules:order="id desc": Sort by document ID in reverse order (newest release)order="views desc": Sort by view count in reverse order (most popular)order="sort desc": Sort by custom order in the background (default behavior). You can choose the appropriate sorting method according to your needs.
limit(Display number)limitThe parameter controls the number of documents to be retrieved and displayed at one time. For example,limit="10"Only the first 10 documents will be displayed. It also supports the "offset" mode, for examplelimit="2,10"means starting from the second document and retrieving 10 items.type(List type)This isarchiveListA very important parameter that determines the purpose and behavior of the list:type="list": The default value, only displaying the specifiedlimitThe number of documents, not involving pagination.type="page": Used for document lists that require pagination. When using this type, it is often配合paginationtags to implement pagination functionality. In addition,qParameters and custom filter parameters only take effect in this type.type="related"Used to retrieve a list of related documents. It is usually used on the document detail page and can recommend related content based on the keywords of the current document or manually associated documents from the backend.
q(search keyword)Whentype="page"then,qThe parameter allows you to specify search keywords to filter the document list. For example,q="seo"Only documents with the 'seo' keyword in the title will be displayed. If the URL already existsq=关键词.archiveListIt will also automatically read and apply.Custom Filter ParameterAnQiCMS supports custom filtering of documents through URL query parameters. If you define additional filterable fields in the content model (such as "house type"), users can filter through
url?房屋类型=住宅This way to filter documents.siteId(Site ID)In a multi-site management environment,siteIdThe parameter allows you to call document data across sites.combineId/combineFromId(Combined document ID)These special parameters are used to create compound document lists, such as 'Travel routes from place A to place B'.They allow you to combine each document in the list with another specified document and reflect this combination relationship when displaying the title and link.
Document fields available in the loop body}
WhenarchiveListAfter obtaining the document set, you can useforLoop through each document and access its various field information. In the loop,itemThis represents the current document object, you can access its properties like this:{{item.Title}}/{{item.Link}}etc.
The following are some commonly used document fields:
Id: The unique ID of the document.Title: Document title.Link: The complete URL link of the document.Description: Brief description of the document.LogoThe cover first image URL of the document.ThumbThe cover thumbnail URL of the document.ImagesThe group image of the document (an array of URLs).CreatedTimeThe document creation timestamp (requiredstampToDatefor formatting).Views: Document views.Flag: The recommended attribute of the document (required)showFlag=trueto display).Category: The classification object of the document (can be accessed directly)item.Category.Titleetc.).- Other field parameters set for document model: By
{% archiveParams params with id=item.Id %}or accessed directly{{item.自定义字段名}}Get it.
Case Study: Diversified content display.
Now, let's demonstrate through several actual code snippetsarchiveListThe powerful function.
Example one: Display the latest article list
{# 显示最新发布的文章,仅限文章模型,前10条 #}
<div class="latest-articles">
<h2>最新文章</h2>
<ul>
{% archiveList articles with moduleId="1" order="id desc" limit="10" %}
{% for article in articles %}
<li>
<a href="{{ article.Link }}">
<img src="{{ article.Thumb }}" alt="{{ article.Title }}">
<h3>{{ article.Title }}</h3>
<p>{{ article.Description }}</p>
<span>发布于: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
</a>
</li>
{% empty %}
<li>暂无最新文章。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Example two: Specific category product list with pagination
Assuming we want to display products under the 'Electronics' category (ID 5) and support pagination.
{# 显示电子产品分类下的产品,带分页功能 #}
<div class="product-category-list">
<h2>电子产品</h2>
{% archiveList products with moduleId="2" categoryId="5" type="page" limit="12" %}
<div class="product-grid">
{% for product in products %}
<div class="product-item">
<a href="{{ product.Link }}">
<img src="{{ product.Logo }}" alt="{{ product.Title }}">
<h3>{{ product.Title }}</h3>
<p>价格: ¥{{ product.Price }}</p>
</a>
</div>
{% empty %}
<p>该分类下暂无产品。</p>
{% endfor %}
</div>
{# 分页导航 #}
<div class="pagination-controls">
{% pagination pages with show="5" %}
<ul>
<li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
{% if pages.PrevPage %}
<li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
{% endif %}
{% for p in pages.Pages %}
<li class="{% if p.IsCurrent %}active{% endif %}"><a href="{{p.Link}}">{{p.Name}}</a></li>
{% endfor %}
{% if pages.NextPage %}
<li><a href="{{pages.NextPage.Link}}">下一页</a></li>
{% endif %}
<li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
</ul>
{% endpagination %}
</div>
{% endarchiveList %}
</div>
Example three: Display related articles on the document detail page.
On the article detail page, it is common to recommend some related articles to the current article to increase user stay time.
{# 在文章详情页显示相关文章,根据关键词推荐 #}
<div class="related-articles">
<h3>相关推荐</h3>
<ul>
{% archiveList relatedDocs with type="related" like="keywords" limit="5" %}
{% for doc in relatedDocs %}
<li>
<a href="{{ doc.Link }}">
<span>{{ doc.Title }}</span>
<span>({{ stampToDate(doc.CreatedTime, "2006-01-02") }})</span>
</a>
</li>
{% empty %}
<li>暂无相关推荐。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Summary
archiveListThe tag is an extremely powerful and flexible component in the AnQiCMS template system. By mastering its various parameters and the document fields available in the loop, you can achieve everything from simple content lists to complex filtering and searching