In AnQi CMS, when we need to dynamically display articles, products, or other document lists on the website, archiveListTags are an indispensable core tool. They provide high flexibility and powerful functionality, whether you want to display the latest content, popular articles, products under specific categories, or even generate lists based on keyword search or customized filtering conditions.archiveListCan easily handle.

archiveListThe core function and basic usage

archiveListTags are mainly used to query and display document collections that meet specific conditions from the database. Its basic usage structure usually includes two parts:archiveListThe tag itself is used to define query conditions as well as aforLoop is used to traverse each document data found.

Here is an example of a typical usage:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
    {% endfor %}
{% endarchiveList %}

In this example:

  • archiveListIs the tag name.
  • archivesIt is a custom variable name used to store the document list data retrieved. You can name it according to your preference.articles/productsetc.
  • with type="list" limit="10"It is used to specify the query parameters.type="list"Indicates that we want to get a simple list, not a paginated list or related document list;limit="10"limits the number of displayed documents to 10.
  • {% for item in archives %}statement is used to traversearchivesEach document data in the variable. Inside the loop,itemThe variable represents the document being processed.
  • {{ item.Link }}and{{ item.Title }}are used to output the current document's link and title.

Flexibly control the acquisition and display of documents

archiveListTags provide rich parameters, allowing us to accurately control which documents to retrieve and how to sort them.

  1. Content location: Specify where to obtain the document

    • moduleId: If your website has multiple content models (such as articles, products), you canmoduleId="1"(Assuming the article model ID is 1) to specify only to retrieve the article model documents.
    • categoryId: Do you want to display documents under a specific category? UsecategoryId="分类ID"If you need to display documents of multiple categories, you can separate multiple IDs with a comma, for examplecategoryId="1,2,3"It is worth noting that if you do not specifycategoryIdIt will try to automatically read the category ID of the current page, and if you want to disable this automatic behavior, you can explicitly set it tocategoryId="0".
    • excludeCategoryId: Sometimes we may need to exclude certain categories of documents, at which point we can useexcludeCategoryId="要排除的分类ID".
    • flag,excludeFlag: Anq CMS supports setting multiple recommended attributes for documents, such as头条[h]/推荐[c]/幻灯[f]etc. Passedflag="c"You can easily retrieve all documents marked as "recommended". Similarly,excludeFlagThe parameter can help you exclude documents with specific attributes.
    • child: By default,categoryIdIt will include the documents under its subcategory. If you only want to get the documents of the specified category itself and not include its subcategory, you can setchild=false.
    • userId,parentId: For documents published by a specific author or documents with parent-child relationships, these parameters also provide precise positioning functionality.
    • siteId: For scenarios of multi-site management, you can go throughsiteIdSpecify the parameter to get data from which site, to achieve cross-site content calling.
  2. Display order and quantity: how to sort and limit the number of items

    • order: The document sorting method is very critical. You can sortidDescending (id desc) to get the latest released documents, or sortviewsDescending (views desc) Show popular content. If you have set custom sorting in the background,order="sort desc"it will display according to your settings.
    • limit: This parameter controls the number of documents displayed in the list, for examplelimit="10"Display 10 items. It also supportsoffset,limitin the form of, for examplelimit="2,10"means starting from the second document and retrieving 10 items.
  3. List type:list/pagewithrelated

    • type="list": This is the simplest list mode, sorted bylimitThe specified parameter quantity is displayed directly in the document.
    • type="page": When you need to add pagination functionality to the document list, you should usetype="page". At this point, you also need to combine with the services provided by Anqi CMS.paginationTag to build pagination navigation, realizing functions such as "Previous page", "Next page", and page jump.
    • type="related"Used to retrieve related documents on the document detail page. It intelligently recommends content based on the current document's categories or other metadata. You can also access it bylike="keywords"Let it match related documents based on keywords orlike="relation"Only display related documents manually set up in the background.
  4. Advanced usage: Search with custom filtering

    • q: Whentype="page"then,qParameters can be used to implement search functionality. You canarchiveListspecify in the tag directlyq="搜索关键词"or, more flexibly, let it automatically read the URL in theqQuery parameters to achieve dynamic display of search results after the user enters keywords in the search box.
    • Filter parameters: If you define additional filterable fields in the background content model for documents (such as the 'type' and 'area' on real estate websites), these filter conditions can be passed to the URL query parameters.archiveListCombined.archiveFiltersLabel, you can build a powerful filtering navigation.
    • combineIdandcombineFromIdThis is a very unique and powerful set of parameters, suitable for scenarios where it is necessary to display two documents together, such as 'a travel route from City A to City B'.They allow you to dynamically append the content of another document to the current document in a list, and reflect this combination relationship in the link.

Document data available in the loop.

Infor item in archivesthe loop,itemThe object contains rich information about the current document, you can call it according to your needs:

  • Basic information:{{ item.Id }}(ID),{{ item.Title }}(Title),{{ item.Link }}(Link),{{ item.Description }}(Description),{{ item.Views }}(Views) etc.
  • Time information:{{ stampToDate(item.CreatedTime, "2006-01-02") }}(Publication time, required)stampToDateformatted).
  • Image information:{{ item.Logo }}(Cover main image),{{ item.Thumb }}(Cover thumbnail). If the document contains multiple images,{{ item.Images }}An image URL array will be returned, you can iterate through it again to display.
  • Category information:{{ item.CategoryId }}(Category ID). To get the category name or link, you usually need to combinecategoryDetailTags such as{% categoryDetail with name="Title" id=item.CategoryId %}.
  • **Custom field