In AnQiCMS, it is a very common requirement for website content operation to obtain and display the list of articles under a specified category.No matter if you want to display the latest articles of a specific category on the homepage, or aggregate all content of a special topic on a standalone page, AnQiCMS's powerful template tag system can help you easily achieve it.
AnQiCMS's template engine syntax is similar to Django, with concise and clear tags and variables, you can directly call backend data in HTML templates. This article will guide you on how to usearchiveListLabel, accurately and efficiently implement the display of article lists.
Step 1: Clarify which category of articles you want to display
Firstly, you need to know the identifier information of the target category. This usually has two methods:
- 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 categories created and their corresponding numeric IDs.For example, the "Company NewsNote down the category ID you need to use.
- Category URL alias (token):If your category is set with a custom URL alias, you can also use this alias to specify the category. This will be very convenient in some dynamic scenarios.
Step 2: UsearchiveListTag to get article data
archiveListAnQiCMS provides a powerful template tag, specifically used for retrieving article lists. Its basic structure is{% archiveList 变量名 with 参数列表 %}," and is{% endarchiveList %}End.withThe keyword followed by, you can pass a series of parameters to accurately control which articles to retrieve.
The following are commonly used parameters when retrieving a list of articles in 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, for examplecategoryId="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).moduleIdUsed to specify the type of article to retrieve the model.The article model's ID is usually 1, and the product model's ID is 2.If you are unsure, you can view it in the 'Content Management' -> 'Content Model' on the backend.type:This parameter determines the type of the list.type="list": Used to get a fixed number of article lists without pagination features. Commonly used in locations such as the homepage and sidebar.type="page":Used to generate article lists with pagination functionality. It is used when you need to display a large number of articles on a category list page, and it is combined withpaginationUse the label.
limit:withtype="list"Use, used to limit the number of articles displayed. For example,limit="5"Only the latest 5 articles will be displayed. If you want to start displaying from the Nth article, you can set it like this:limit="2,5"(Indicates starting from the 2nd article and displaying 5 articles)。order:Define the sorting method of the articles. Common values include:order="id desc":Sort articles by article ID in descending order (usually meaning the most recently published articles are at the top).order="views desc":Sort articles by the number of views in descending order (popular articles at the top).order="sort desc":Sorted in descending order by the sorting value set in the background (can manually adjust the order of articles).
child:Whether the articles include sub-category articles.child="true"It will include articles in the specified category and all its subcategories;child="false"It only includes the direct articles of the specified category.flag:Filter based on the recommended attributes of the articles. For example,flag="c"Get recommended articles.flag="h"Get headline articles.
Step 3: Traverse and display article details.
archiveListTags will return an array of article objects, you need to use{% for ... %}Loop through these articles and display their details one by one.
Inside the loop, each article object usually has a default variable name (for example, in the example, if you define it asarticles, then the variable inside the loop body isarticle)。ThisarticleThe variable includes various fields of the article, you can directly call it.{{ article.字段名 }}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 needing to be usedstampToDateLabel formatting){{ article.Views }}Article views{{ article.CategoryId }}: Article category ID
**Tips for time formatting}