How to use the `archiveList` tag to get the article list and support sorting by ID, views, or custom sorting?

Calendar 👁️ 75

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.

Related articles

How to get the list of all single pages or the detailed content of a specific single page in AnQiCMS template?

As a senior security CMS website operator, I am well aware of the importance of high-quality, well-structured content for website user experience and search engine optimization.A single page is the core of a website's basic information display, such as "About Us", "Contact Information", and "Terms of Service", etc.In AnQiCMS, through the powerful template tag system, we can flexibly obtain and display the content of these single pages. I will elaborate in detail on how to obtain the list of all single pages and the detailed content of a specific single page in the AnQiCMS template.###

2025-11-06

How to get the details of the current access category, including the title, link, description, and custom fields?

As an experienced CMS website operator, I am well aware of the importance of high-quality and easily accessible content information for website user experience and search engine optimization.In Anqi CMS, obtaining detailed information about the current visited category is a very basic and frequent requirement in website construction. Whether it is used for page titles, navigation breadcrumbs, or detailed introductions on category pages, it is necessary to accurately call these data.Our AnQi CMS provides a powerful and flexible template tag system, making it extremely easy to obtain the title, link, description, and even custom fields of the current visited category

2025-11-06

How to use the `categoryList` tag to get and loop through the category list under a specified content model?

As an expert who has been deeply engaged in AnQiCMS content operations for a long time, I know the importance of the category list in website structure and user experience.Make flexible use of the `categoryList` tag, which can help us efficiently organize content, build a clear navigation system, and provide readers with a more accurate content discovery path.Below, I will elaborate on how to use the `categoryList` tag to retrieve and display the category list of a specified content model in a loop.## Use AnQiCMS's `categoryList`

2025-11-06

How to implement dynamic breadcrumb navigation in AnQiCMS template and customize the home page text?

As a senior security CMS website operator, I know that high-quality content and excellent user experience are the foundation of website success.With the powerful functions of AnQiCMS, we can not only efficiently manage content, but also provide users with a smooth and intuitive browsing experience through fine-tuned template customization.Today, let's delve deeply into how to implement dynamic breadcrumb navigation in the AnQiCMS template, and flexibly customize the home page text to enhance the usability and search engine friendliness of the website.

2025-11-06

How to implement complete pagination functionality for the article list in AnQiCMS template?

As an expert deeply familiar with the operation of AnQiCMS, I know that a smooth, user-friendly website experience is crucial for attracting and retaining users.The pagination feature of a content list is the cornerstone of any content-intensive website, not only optimizing the user's browsing experience, but also an important aspect of search engine optimization.In AnQiCMS, achieving complete pagination for the article list is efficient and flexible through its powerful template tag system.

2025-11-06

How to get the title, link, and thumbnail of the previous and next articles of the current article?

As an experienced website manager familiar with the operation of Anqi CMS, I fully understand the importance of the details of content presentation to user experience and the overall performance of the website.The front and rear navigation function of the article detail page can not only effectively guide users to continue browsing and reduce the bounce rate, but also is an effective means to enhance the relevance between pages and optimize the internal link structure.An enterprise CMS provides a concise and efficient template tag, allowing us to easily achieve this function.--- ### Enhance Content Coherence: Implement Previous and Next Article Navigation in AnQiCMS In Website Content Operation

2025-11-06

How to display a list of recommended articles related to the current article content, supporting keyword search or manual association?

As an experienced CMS website operation person in the security industry, I know that high-quality content and accurate recommendations are important for improving user experience and website SEO.In the article detail page, effectively displaying recommended articles related to the current content can not only extend the user's visit time and reduce the bounce rate, but also optimize and improve the page weight and crawling efficiency through internal links.AnQi CMS provides flexible tags, supporting us to build this recommendation list through keywords or manual methods.### Implementing related article recommendations in AnQi CMS AnQi CMS uses a powerful template tag system

2025-11-06

How to retrieve and display the custom parameter field value of the article through template tags in AnQiCMS?

In AnQiCMS (AnQiCMS), the custom parameter field provides great flexibility and scalability for website content.As a website operator familiar with AnQi CMS, I am well aware of how to effectively utilize these fields and display them on the website front end to meet diverse content display needs.This article will elaborate on how to use the AnQi CMS template tags to obtain and display the custom parameter field values of the article.### Understanding the customized parameter fields of AnQi CMS AnQi CMS allows users to customize the content model according to business needs

2025-11-06