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 features, whether you want to display the latest content, popular articles, products under specific categories, or even generate lists based on keywords or custom filtering conditions.archiveListCan handle everything easily.

archiveListThe core functions and basic usage

archiveListTags are mainly used to query and display a collection of documents 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 aforThe loop is used to iterate over each document data retrieved in the query.

A typical usage example is as follows:

{% 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 list of documents retrieved. You can name it according to your preference.articles/productsetc.
  • with type="list" limit="10"It is used to specify the query conditions parameter.type="list"The value indicates that we want to get a simple list, rather than a paged list or related document list;limit="10"limits the number of displayed documents to 10.
  • {% for item in archives %}The statement is used to traversearchivesEach document data in the variable. Inside the loop,itemThe variable represents the document currently being processed.
  • {{ item.Link }}and{{ item.Title }}are used to output the current document's link and title.

Flexible control over document retrieval and display

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 that only the documents of the article model should be retrieved.
    • 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 commas, 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".
    • excludeCategoryIdSometimes we may need to exclude certain categories of documents, in which case we can useexcludeCategoryId="要排除的分类ID".
    • flag,excludeFlagSafeCMS supports setting various recommended attributes for documents, such as头条[h]/推荐[c]/幻灯[f]etc. Throughflag="c"You can easily retrieve all documents marked as "recommended". Similarly,excludeFlagparameters can help you exclude documents with specific properties.
    • child: By default,categoryIdIt will include documents from its subcategories. If you only want to get documents from the specified category itself and not include its subcategories, you can setchild=false.
    • userId,parentId[en]: For documents published by specific authors or documents with parent-child relationships, these two parameters also provide precise positioning functionality.
    • siteId[en]: In scenarios of multi-site management, you can usesiteIdParameters specify which site's data to retrieve, achieving cross-site content calls.
  2. Display order and quantity: how to sort and limit the number of items

    • orderThe document's sorting method is very critical. You can according toidDescending (id desc) to get the latest released documents, or to sort byviewsDescending (views descDisplay popular content. If you have set custom sorting in the background,order="sort desc"it will be displayed according to your settings.
    • limit: This parameter controls the number of documents displayed in the list, for example,limit="10"Display 10 items. It also supportsoffset,limitin the form of, such aslimit="2,10"This indicates starting from the second document and fetching 10 data items.
  3. List type:list/pageWithrelated

    • type="list": This is the simplest list mode, sorted bylimitthe number of parameters specified, and directly displays the documents.
    • type="page"When you need to add pagination functionality to the document list, you should usetype="page". At this time, you also need to combine with the provided by Anqi CMSpaginationTo build pagination navigation using tags, and to implement features such as "Previous Page
    • type="related"[en] Used to retrieve related documents on the document detail page. It intelligently recommends content based on the current document's category or other metadata. You can also throughlike="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 filters

    • qWhentype="page"whenqParameters can be used to implement search functionality. You can directly specifyarchiveListin the tagq="搜索关键词", or more flexibly, let it automatically read the URL inqQuery parameters, thus realizing dynamic search results display in the search box after the user enters keywords.
    • Filter parametersIf you define additional filterable fields for documents in the background content model (such as 'house type', 'area' on real estate websites, etc.), these filter conditions can be passed to the URL query parameters.archiveList. Combined,archiveFiltersTags, you can build powerful filtering navigation.
    • combineIdandcombineFromIdThis is a very unique and powerful set of parameters, suitable for scenarios where two documents need to be combined and displayed 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 the list and reflect this combination relationship in the link.

Document data available within the loop.

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

  • Basic information:{{ item.Id }}(ID),{{ item.Title }}(Title),{{ item.Link }}(Link),{{ item.Description }}(Description),{{ item.Views }}(Views) et al.
  • Time information:{{ stampToDate(item.CreatedTime, "2006-01-02") }}(Publish time, required)stampToDate(Formatted)).
  • Image information:{{ item.Logo }}(Cover first image),{{ item.Thumb }}(Cover thumbnail). If the document contains multiple images,{{ item.Images }}it will return an array of image URLs, which you can iterate through again to display.
  • category information:{{ item.CategoryId }}(Category ID). To get the category name or link, usually you need to combinecategoryDetailtags, such as{% categoryDetail with name="Title" id=item.CategoryId %}.
  • **Custom fields**