As an experienced Anqi CMS website operations personnel, I fully understand that efficient content management is crucial for attracting and retaining users. The template tag system provided by Anqi CMS is its strong point, among whicharchiveListLabels are the core of daily content display. They can help us flexibly extract articles, products, and other content from the database and display them in the way we want.

UnderstandingarchiveListThe core role of tags

In the template design of AnQi CMS,archiveListTags play the role of a content list generator. Whether you want to display the latest articles on the homepage, list related products on the category page, or recommend related content on the article detail page,archiveListCan meet all your needs. It allows you to precisely control what content to obtain, how to filter it, and in what order to present it.

UsearchiveListWhen, you will usually wrap it in a{% archiveList 变量名称 ... %}and{% endarchiveList %}tag pair. Among them,变量名称is a variable name you customize for the list of content you get, for example,archivesorproductsthis variable will be inside the tags,forLoop usage.

A basicarchiveListThe structure will look like this:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <div class="article-item">
            <a href="{{item.Link}}">{{item.Title}}</a>
            <p>{{item.Description}}</p>
            <span>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            <span>浏览量: {{item.Views}}</span>
        </div>
    {% empty %}
        <p>当前列表没有任何内容。</p>
    {% endfor %}
{% endarchiveList %}

Here, archivesIt is our content list variable,itemIsforThe temporary variable for the current content in the loop.emptyThe tag provides a graceful way to handle the case when the list is empty.

Precise filtering: controls the source of the content

archiveListProvided with a variety of parameters to accurately filter the content you want to display.

first, moduleIdParameters allow you to specify the model to which the content belongs, for examplemoduleId="1"may represent the article model, andmoduleId="2"May represent a product model. This ensures that you are getting specific content.

secondly,categoryIdThe parameter is used to retrieve content from a specific category. You can specify a single category ID (categoryId="1"),can also specify multiple category IDs(categoryId="1,2,3")。If you want to get the content of the category of the current page, but do not want to hard-code the ID,archiveListIt will automatically read the current page's category ID. If you do not want it to be read automatically, you can explicitly set it.categoryId="0"。“Furthermore,”excludeCategoryIdIt allows you to exclude content of specific categories.

userIdThe parameter can be used to retrieve articles published by a specific author, andparentIdit is used to retrieve the sub-documents of a specified superior document, which is very useful when building a multi-level content structure.

For content with recommended attributes (such as headline, recommendation, slideshow, etc.),flagthe parameters can help you filter out these specially marked content, such asflag="c"Articles marked as "recommended" will be displayed accordingly.excludeFlagContents with specific attributes can be excluded. If you need to display attributes on the front end,flagyou can setshowFlag=true.

in the list display,qThe parameter can be used to perform keyword search, it will match the title of the content. If the URL already existsq=关键词.archiveListIt can also automatically recognize and apply.

Flexible sorting: Displayed by ID, views, or custom order

archiveListOne of the most powerful features is its flexible sorting mechanism, throughorderParameters, you can easily control the display order of content.

Sort by IDTo sort articles by ID (usually representing the publish time, as IDs are auto-incremented), you can setorder="id desc"to display the most recently published content (the larger the ID, the newer), ororder="id asc"Show the earliest published content.

Sorted by views: To highlight popular articles or products, you can sort by views. Setorder="views desc"will put the most viewed content at the forefront, whileorder="views asc"the opposite is true.

Sort by custom order: AnQi CMS allows custom sorting of content in the background. If you manually adjust the order of content in the background and want the front-end to display it in this order, you can useorder="sort desc". By default, if not specifiedorderparameter,archiveListit will also be sorted according to the custom sorting of the background (sort desc) to display the content.

The following is an example of sorting parameters:

{# 按照最新发布(ID降序)排序的前10篇文章 #}
{% archiveList archives with order="id desc" limit="10" %}
    {% for item in archives %}
        <p>最新文章: {{item.Title}}</p>
    {% endfor %}
{% endarchiveList %}

{# 按照浏览量最高(views降序)排序的前5篇热门文章 #}
{% archiveList hot_articles with order="views desc" limit="5" %}
    {% for item in hot_articles %}
        <p>热门文章: {{item.Title}} (浏览量: {{item.Views}})</p>
    {% endfor %}
{% endarchiveList %}

{# 按照后台自定义排序的前8个产品 #}
{% archiveList custom_products with moduleId="2" order="sort desc" limit="8" %}
    {% for item in custom_products %}
        <p>推荐产品: {{item.Title}}</p>
    {% endfor %}
{% endarchiveList %}

Control the number and pagination display

limitParameters are used to control the number of contents obtained each time. For example,limit="10"only 10 contents will be displayed.limitIt also supports the "offset" mode, for example,limit="2,10"Start from the third item, get 10 items (skip the first 2).

typeThe parameter determines the display form of the list. Whentype="list"Then, it will only display content according tolimitthe specified number. Whiletype="page"When, it will enable the pagination feature, usually withpaginationtags used together to build a complete page navigation.

Combine related content with advanced features

archiveListAlso supports retrieving related content. Whentype="related"At the time, the label will intelligently find nearby documents of the same category based on the current document ID. You can alsolike="keywords"let it find related content based on the keywords of the document orlike="relation"To accurately match the relevant documents manually set up in the background.

Advanced usage includes.combineIdandcombineFromIdThese parameters allow you to attach another document to the list, thereby creating complex combined titles and links.For example, you can use this feature to generate content such as 'a travel route from Beijing to Shanghai', where 'Beijing' and 'Shanghai' are two independent documents but are cleverly combined when displayed in a list.In this case, you can use{{combine.Title}}or{{combineArchive.Title}}To refer to the fields of the combined document.

Summary

archiveListTags are an indispensable tool in the design of Anqi CMS templates. By flexibly using itsmoduleId/categoryId/flagand other filtering parameters, combinedorderparameters to achieve sorting by ID, views, or custom order, as well aslimitandtypeParameters for quantity control and pagination management, allowing website operators to easily build efficient content lists that meet various business needs, thereby enhancing user experience and the attractiveness of website content. Proficient in masteringarchiveListThe use of tags will greatly improve your content management efficiency and the flexibility of your website.


Frequently Asked Questions (FAQ)

1.archiveListlabel'sorderWhat sorting methods do the parameters support? orderParameters support various sorting methods to control the display order of content. Commonly including sorting by ID in descending order (order="id desc"), or ascending order (order="id asc"), descending order by page views (order="views desc"), or ascending order (order="views asc"), and custom sorting by backend (order="sort desc"If not specifiedorderThe parameter defaults to using the background custom sorting

2. How toarchiveListTo get the content of multiple categories at the same time?You can specify only the top-level categories by using thecategoryIdMultiple category IDs are separated by commas in the parameter, for examplecategoryId="1,5,8"Like thisarchiveListIt will return all content under these three categories. If you want to get all category content, you can omitcategoryIdorcategoryListthe tagall=trueAfter getting all categories, call them separately in a looparchiveList.

3.archiveListoftype="page"andtype="list"What is the difference?Whentype="list"then,archiveListOnly based onlimitThe specified number returns a content list without pagination. Whiletype="page"then,archiveListPage data is generated for the content list, usually requiring to be used with{% pagination %}Use labels together to display page navigation and switch pages on the front end.type="page" 通常 used for category list pages, search result pages, and other scenarios that require displaying a large amount of content with pagination.