How to aggregate and display the content list of multiple article categories on a single page?

Calendar 👁️ 71

In AnQi CMS, implementing a single-page aggregation display of multiple article category content lists is a very practical need. It can help website administrators organize content efficiently and provide visitors with a more convenient browsing experience.This is commonly applied to the homepage, special page, or aggregation page of a website, where we can easily achieve this goal by skillfully using AnQiCMS template tags.

Core idea: Tag combination and nested loop

AnQi CMS provides a flexible template tag system, among whichcategoryListandarchiveListare two core players in the aggregation display of content. Our basic idea is:

  1. Firstly, get the list of categories you want to aggregate and display.This may be a top-level category or a subcategory under a parent category.
  2. Then, traverse these categories.In each loop, we will get the detailed information of the current category.
  3. Within each category, we will get the list of articles under the current category ID and display them.This way, each category of articles will be displayed in an independent block on the page.

By using this combination of tags and nested loops, we can clearly display multiple categories and their included article content on a single page.

Preparation: Understand the template structure and content model

Before you start, it is recommended that you confirm the structure and content model of your AnQiCMS template. The template files of AnQiCMS are usually stored in/templateUnder the directory, with.htmlwith suffix. You can choose to place these codes in the homepage template of the website (index.html), on a single page (page/detail.html) or create a custom template for a specific aggregated page to place these codes.

In addition, AnQiCMS supports flexible content models such as 'Article Model', 'Product Model', etc.When retrieving the category and article list, you must be clear about which content model's data you want to obtain, as different models have their own independent categories and article data. This is throughmoduleIdSpecify the parameter, for example,moduleId="1"typically represents an article model,moduleId="2"Represents the product model.

The application of key template tags

1.categoryList: Get the category list

categoryListThe tag is used to retrieve the list of categories of the website. We can use it to filter out the categories that need to be displayed on the page.

  • moduleId: Specify the content model ID, for examplemoduleId="1"(Article model).
  • parentId: Specify the parent category ID.parentId="0"Indicates retrieving all top-level categories. If you want to get the subcategories under a specific category, you can fill in the category ID.
  • Loop variableitemCommon fields:Id(Category ID),Title(Category Name),Link(Category Link),Description(Category Description) etc.

2.archiveList: Get article list

archiveListTags are to obtain the core tags of articles (or products, dependingmoduleId) listed.

  • type="list": It indicates displaying in list form, usually paired withlimitParameter.
  • categoryId: This is the most critical parameter, it will be connected with externalcategoryListBinding the category ID in the loop, make sure to get the articles under the current category.
  • moduleId: Similarly, you need to specify the content model ID, withcategoryListofmoduleIdremain consistent.
  • limit: Control the number of articles displayed under each category, for examplelimit="6"It indicates that 6 articles are displayed under each category.
  • order: Specify the sorting method of the articles, for exampleorder="id desc"(Sorted by ID in descending order, i.e., the most recent published),order="views desc"(Sorted by views in descending order).
  • Loop variablearchiveCommon fields:Id(Article ID),Title(Article Title),Link(Article Link),Description(Article Summary),Thumb(Thumbnail),CreatedTime(Published time),Views(Views) et al.

3.forLoop and conditional judgment

forLoop is to traversecategoryListandarchiveListThe basic way to return list data.ifCondition judgment is used to control the display of content under specific conditions, such as checking if there is a thumbnail, or handling the case of an empty list.

4.stampToDateTime formatting:

When displaying the article publish time,archive.CreatedTimeit returns a timestamp, we can usestampToDatetags to format it into an easily readable date format, such as{{stampToDate(archive.CreatedTime, "2006-01-02")}}.

5.categoryDetail: Get category details

although incategoryListofforAccess directly in a loopitem.Titleanditem.LinkBut in some cases where more detailed categorization information is needed (such as categorization imagesLogoorThumb),categoryDetailLabel combinationid=item.IdParameters will be more convenient to use.

Practical code example: Aggregate display of articles in multiple categories

Assuming we want to aggregate and display several top-level categories under the 'article model' on the homepage. You can do this in your homepage template file (for example/template/default/index.htmlAdd the following code inside the brackets:

”`twig {# External loop: get the top-level category list of the article model #} {% categoryList categories with moduleId=“1” parentId=“0” %}

{% for item in categories %}
<div class="category-block">
    {# 显示分类标题和链接 #}
    <h3 class="category-title">
        <a href="{{ item.Link }}" title="更多{{item.Title}}">{{item.Title}}</a>

Related articles

How to completely customize the content display layout of the article detail page?

In AnQi CMS, creating a unique and richly detailed article page is not difficult.This is not just a modification of the style, but also goes deep into every link of content structure, data retrieval, and front-end rendering, achieving true 'complete customization'.AnQi CMS provides us with great flexibility in content models and powerful template engines, enabling us to achieve this goal. ### Understanding the "skeleton" of the article detail page: template mechanism To customize the article detail page, you first need to understand the template mechanism of Anqi CMS.In Anqi CMS

2025-11-09

How to efficiently display the latest list of articles released in Anqi CMS?

In AnQi CMS, effectively displaying the latest list of published articles is the foundation of website content operation, which can help keep your website vibrant and allow visitors to get the latest information first.AnQi CMS provides flexible and powerful template tags, allowing you to easily achieve this goal.Understanding the Core: The Charm of `archiveList` Tag To display the latest published article list, we mainly rely on the `archiveList` template tag built into AnQiCMS.This tag is used to retrieve various documents on the website (such as articles

2025-11-09

How to generate and manage a Sitemap to enhance the visibility of website content in search engines

For any website that hopes to stand out in search engines, Sitemap is an indispensable tool.It is like a detailed map of your website content, indicating all pages that can be crawled and indexed by search engine spiders (crawlers).In AnQi CMS, generating and managing a Sitemap is an efficient and user-friendly task that can significantly enhance the visibility of your website content.What is a Sitemap and why is it important?Sitemap, in short, is a website map.It is an XML file

2025-11-09

How can you use the content collection feature to quickly fill a large amount of content to be displayed?

Running a website, the most annoying thing is filling content.Whether it is a new site going online that needs to quickly accumulate a large amount of basic content, or an existing website that needs to maintain continuous updates to attract and retain users, manually writing or organizing content is a time-consuming and labor-intensive task.Today in content marketing and SEO optimization, how to efficiently and in bulk acquire and manage the content to be displayed has become a challenge for many operators.AnQiCMS (AnQiCMS) understands this pain point and its built-in content collection function is specifically designed to solve this problem.It is not simply copy and paste

2025-11-09

How to implement multilingual front-end display and switching of website content in AnQiCMS?

When building a website for global users, the display and switching of multilingual content are essential.AnQiCMS (AnQiCMS) understands the importance of this requirement and has integrated powerful multilingual support capabilities into the system design from the beginning, helping websites easily achieve internationalization of content. ### The Basics of Content Multilingual Management: Multi-Site Mode One of the core mechanisms for implementing multilingual display of website content in Anqi CMS is its flexible "Multi-Site Management" function.For a truly multilingual website

2025-11-09

How to configure pseudo-static URL rules to optimize the search engine display of website content?

In today's internet environment, the search engine display effect of website content is directly related to traffic and conversion.A clear and meaningful URL structure not only enhances user experience but is also an indispensable part of search engine optimization (SEO).AnQiCMS (AnQiCMS) understands this and therefore provides a powerful and flexible pseudo-static URL rule configuration function to help website managers easily optimize URL structure.Why configuring pseudo-static URL rules is crucial for the search engine display of website content?Before getting to know how to configure

2025-11-09

How to correctly parse and display Markdown formatted text in article content?

In Anqi CMS, using Markdown format to write articles is an efficient and elegant way of content creation, which makes our content structure clearer and layout more flexible.Especially for technical articles that need to include code, mathematical formulas, and even flowcharts, Markdown editors are an indispensable tool.How can we ensure that these carefully written Markdown texts are correctly parsed and perfectly presented on the website front-end?Let's explore step by step. ### Enable Markdown Editor First

2025-11-09

How to customize the display layout of different types of content in AnQiCMS?

## Unlock AnQiCMS: The Secret Weapon of Personalized Content Layout In the digital age, a website is not just a carrier of information, but also the core of brand image and user experience.A system that can flexibly customize the display layout of content, which is undoubtedly the key to improving operational efficiency and user attraction for small and medium-sized enterprises, self-media operators, and multi-site managers.AnQiCMS with its powerful content model and flexible template mechanism provides us with all the tools to achieve this goal. Today

2025-11-09