In website content operation, we often need to display a list of articles under a specific category on a single page, and in order to provide a better user experience and content structure, pagination functions are usually used in conjunction.A strong and easy-to-use template tag provided by AnQi CMS can help us easily achieve this requirement.

The core of article content calling:archiveListTag

To call the article content under a specific category, Anqi CMS providesarchiveListthis core tag. This tag is very flexible and can filter and sort articles based on various conditions.

It is crucial to clearly specify the category to be called. This is achieved throughcategoryIdparameters. For example, if the category ID of your 'Company News' is 10, you can set it like this:categoryId="10"If you need to call articles of multiple categories at once, you can separate the category IDs with English commas, for examplecategoryId="10,12,15"A notable detail is, if omittedcategoryIdThe parameter, the system will try to read the category ID of the current page; if you explicitly do not want it to be read automatically, you can set it tocategoryId="0".

Next, to implement the pagination display of the article list,typeThe parameter must be set to"page". Whentype="page"then,archiveListThe label will intelligently return the article data of the current page and simultaneously generate other information required for pagination, which will be used by subsequent pagination labels.

In addition to these two key parameters,archiveListIt supports other commonly used settings to meet various display needs:

  • limit: Controls the number of articles displayed per page, for examplelimit="10"means 10 articles per page.
  • order: Defines the sorting method of the articles, for example"id desc"Means sorting by article ID in reverse order (i.e., the most recent published),"views desc"The items are sorted by the number of views in descending order.
  • moduleIdIf your website uses a different content model (such as articles, products, etc.), you can specify the model ID through this parameter. The article model is usually set to 1 by default.

InarchiveListWithin the loop of the tag, you can accessitemthe detailed information of each article, including{{item.Title}}(Article Title),{{item.Link}}(article link),{{item.Description}}(Article summary),{{item.Thumb}}(article thumbnail),{{item.CreatedTime}}(Publishing time) and{{item.Views}}(Views) and others, thus enabling flexible construction of the display style for each article.

Improve pagination navigation:paginationTag

paginationTags are witharchiveListTags (whentype="page"Used in conjunction with (time), it is responsible for generating beautiful and functional pagination navigation links at the bottom of the page.

While usingpaginationtags, you can go throughshowparameter to control the number of page numbers displayed in the pagination bar. For example,show="5"It will display 5 page links before and after the current page number, making the pagination bar appear more concise and easy to navigate.

paginationThe tag will provide a name forpagesThe variable, which contains all the data related to pagination, for example{{pages.TotalItems}}(Total number of articles),{{pages.TotalPages}}(Total number of pages),{{pages.CurrentPage}}(Current page) and so on. What's most important is that it provides links and status information for the home page, previous page, next page, last page, and middle page numbers.These pagination links are also a list, you can utilizeforLoop to iterate, and throughpageItem.IsCurrentTo judge the current page, thus highlighting.

Practice exercise: Call specific category articles and implement pagination

Here is a specific code example demonstrating how to implement the calling and pagination display of articles in a specific category of Anqi CMS template. Suppose we want to display it in a template file such asarticle/list.htmlOr you can display all articles under the custom template you set for a specific category, and perform pagination.

`twig {# This is the page content area, used to display the list of articles #}