As a senior security-oriented CMS website operations personnel, I am well aware of the importance of efficient content management for attracting and retaining users. The template tag system provided by Anqi CMS is one of its strengths, among whicharchiveListTags are the core of daily content display. They help us flexibly extract articles, products, and other content from the database and sort and display them in the way we want.

UnderstandingarchiveListThe core function of the tag

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 category pages, or recommend related content on article detail pages,archiveListCan meet all your needs. It allows you to precisely control which content to obtain, how to filter it, and the order in which it is presented through a series of parameters.

UsearchiveListWhen, you would usually wrap it in a{% archiveList 变量名称 ... %}and{% endarchiveList %}tag pair. Among,变量名称is a variable name you customize for the content list you obtain, for example,archivesorproducts, this variable will be inside the tags.forUsed in the loop.

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,archivesIs our content list variable,itemYesforThe temporary variable of the current content in the loop.emptyTags provide an elegant way to handle the case where a list is empty.

Precise filtering: control the source of content.

archiveListProvides various parameters for precise filtering of the content you want to display.

Firstly,moduleIdThe parameter allows you to specify the model to which the content belongs, for examplemoduleId="1"may represent the article model, whilemoduleId="2"may represent the product model. This ensures that you are getting content of a specific type.

Secondly,categoryIdParameters used to fetch content from a specific category. You can specify a single category ID (categoryId="1"), or specify multiple category IDs (categoryId="1,2,3")。If you want to get the content of the category to which the current page belongs, 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 read automatically, you can explicitly set it.categoryId="0"In addition,excludeCategoryIdthen it allows you to exclude content of specific categories.

userIdParameters can be used to retrieve articles published by a specific author,parentIdand is used to retrieve the subordinate documents of a specified superior document, which is very useful when constructing multi-level content structures.

For content with recommendation attributes (such as headline, recommendation, slideshow, etc.),flagthe parameters can help you filter out these special marked contents, such asflag="c"The articles marked as "Recommended" will be displayed. Correspondingly,excludeFlagcontent with specific properties can be excluded. If you need to display specific properties on the front-end,flagyou can setshowFlag=true.

in the list display,qParameters can be used for keyword search, it will match the title of the content. If the URL already existsq=关键词Query parameters,archiveListit can also automatically recognize and apply.

Flexible Sorting: Display by ID, views, or custom order

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

Sort by IDTo sort by the article's ID (usually representing the publish time, as IDs are auto-incrementing), you can setorder="id desc"Show the latest released content (the higher the ID, the newer), ororder="id asc"Show the earliest released content.

Sort by view countTo highlight popular articles or products, you can sort by views. Setorder="views desc"will place the content with the highest views at the forefront, whileorder="views asc"the opposite is true.

Sort by custom orderThe :SafeCMS allows for custom sorting of content in the backend. If you manually adjust the order of content in the backend and wish to display it according to this order on the frontend, you can useorder="sort desc"By default, if not specifiedorderparameters,archiveListit will also be displayed according to the custom sorting of the backgroundsort desc). Display content accordingly.

Here 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

limitThe parameter is used to control the number of contents retrieved each time. For example,limit="10"Only 10 items will be displayed.limitIt also supports the "offset" mode, for examplelimit="2,10"Starting from the third item, 10 items will be retrieved (skipping the first two).

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

Combine related content with advanced features.

archiveListAlso supports fetching related content. Whentype="related"When, the tags will intelligently find nearby documents of the same category based on the current document's ID. You can alsolike="keywords"let it find related content based on the document's keywords, orlike="relation"To precisely match the relevant documents manually set up by the background.

More advanced usage includes:combineIdandcombineFromIdThese parameters allow you to attach another document to the list, thereby creating complex composite titles and links.For example, you can use this feature to generate content such as "Travel route from Beijing to Shanghai{{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 utilizing itsmoduleId/categoryId/flagetc. filtering parameters, combinedorderparameters to achieve sorting by ID, views, or custom order,limitandtypeParameter quantity control and pagination management are implemented, allowing website operators to easily build efficient content lists that meet various business needs, thereby enhancing user experience and the attractiveness of website content. Mastery is required.archiveListThe use of tags will greatly improve your content management efficiency and website flexibility.


Common Questions and Answers (FAQ)

1.archiveListTagsorderWhat sorting methods does the parameter support? orderParameters support multiple sorting methods to control the display order of content. Common ones include descending by ID (order="id desc"), ascending by ID (order="id asc"), descending by views (order="views desc"), ascending by ID (order="views asc"), and custom sorting by the backend (order="sort desc")。If not specifiedorderparameters, the default will be the background custom sorting.

2. How toarchiveListget the content of multiple categories at the same time?You can check if the content is empty bycategoryIdThe parameter uses commas to separate multiple category IDs, for example,categoryId="1,5,8".archiveListThis will return all content under these three categories. If you want to get all category content, you can omit,categoryIdor incategoryListspecified in the tagall=trueAfter obtaining all categories, call them separately through a looparchiveList.

3.archiveListoftype="page"andtype="list"What is the difference?Whentype="list"whenarchiveListOnly based onlimitReturn a content list specified by the number of parameters, without pagination functionality. Whiletype="page"whenarchiveListGenerates pagination data for content lists, usually used with{% pagination %}tags to display page navigation and switch pages on the frontend.type="page"Used commonly for category list pages, search result pages, and other scenarios that require pagination to display a large amount of content.