It is a very common requirement in website content operation to retrieve and display a list of articles under a specified category in AnQiCMS.Whether you want to display the latest articles of a specific category on the homepage or aggregate all content of a special topic on an independent page, AnQiCMS' powerful template tag system can help you achieve it easily.

AnQiCMS's template engine syntax is similar to Django, using concise and clear tags and variables, you can directly call backend data in HTML templates. This article will guide you on how to make use ofarchiveListLabel, accurately and efficiently implement the display of the article list.

Step 1: Clarify which category of articles you want to display.

First, you need to know the identifier information of the target category. This usually has two ways:

  1. Category ID:This is the most direct way. Log in to your AnQiCMS backend, go to "Content Management" -> "Document Categories".Here, you can find all the categories created and their corresponding numeric ID.For example, the 'Company News' category may correspond to ID 1, and the 'Industry Dynamics' may correspond to ID 2.Write down the category ID you need to use.
  2. Category URL alias (token):If your category is set to custom URL alias, you can also use this alias to specify the category. This will be very convenient in certain dynamic scenarios.

Second step: usearchiveListTags retrieve article data

archiveListIt is a powerful template tag provided by AnQiCMS, specifically used for retrieving article lists. Its basic structure is{% archiveList 变量名 with 参数列表 %}, and ends with:{% endarchiveList %}End. InwithAfter the keyword, you can pass a series of parameters to accurately control which articles to retrieve.

The following are common parameters used when retrieving a list of articles for a specified category.

  • categoryId:This is a key parameter used to specify which category of articles to retrieve. You can pass a single category ID, such ascategoryId="1"If you need to get articles of multiple categories, you can separate them with commas, for examplecategoryId="1,3,5".
  • moduleId:AnQiCMS supports various content models (such as articles, products, etc).moduleIdSpecify which type of model article to retrieve. Typically, the article model ID is 1, and the product model ID is 2.If you are unsure, you can check it in the "Content Management" -> "Content Model" in the background.
  • type:This parameter determines the type of the list.
    • type="list": Used to get a fixed number of article lists without pagination features. Often used in the homepage, sidebar, and other locations.
    • type="page"Used to generate a paginated list of articles. It is used when you need to display a large number of articles on a category list page, and it is combined withpaginationlabel usage
  • limit:cooperatetype="list"Use, to limit the number of articles displayed. For example,limit="5"Only the latest 5 articles will be displayed. If you want to start from the Nth article, you can set it like this:limit="2,5"Starting from the second article, displaying 5 articles.
  • order:Define the sorting method of the articles. Common values include:
    • order="id desc":Sort by article ID in descending order (usually meaning the most recently published articles are at the top).
    • order="views desc":Sort by article views in descending order (popular articles are at the top).
    • order="sort desc": Arrange in descending order according to the sorting value set in the background (article order can be manually adjusted).
  • child:Whether the article includes subcategory articles.child="true"The default setting includes articles of the specified category and all its subcategories;child="false"It only includes the direct articles of the specified category itself.
  • flag:Filtered based on the recommended attributes of the articles. For example,flag="c"Get recommended articles,flag="h"Get the headline article.

Step three: Traverse and display the article details.

archiveListThe tag will return an array of article objects, you need to use{% for ... %}Loop to traverse these articles and display their details one by one.

Within the loop, each article object usually has a default variable name (for example, in the example, if you define it asarticlesthen the variable inside the loop body isarticle)。ThisarticleThe variable includes various fields of the article, you can directly pass through{{ article.字段名 }}Call in the form.

Common article fields include:

  • {{ article.Title }}: Article title
  • {{ article.Link }}: Article link
  • {{ article.Description }}: Article Summary
  • {{ article.Thumb }}: Article thumbnail address
  • {{ article.Logo }}: Article cover first image address
  • {{ article.CreatedTime }}: Article publish time (this is a timestamp, usually need to bestampToDateformatted with tags)
  • {{ article.Views }}: Article views
  • {{ article.CategoryId }}: Article Category ID

**Tip for Time Formatting