How to get and display the document list of the specified category and model in AnQiCMS using the `archiveList` tag?

Calendar 👁️ 55

In AnQi CMS, efficiently managing and displaying website content is the key to improving user experience and search engine rankings.In order to achieve this goal, we often need to organize and display document lists according to specific categories or content models. At this point,archiveListTags have become a powerful tool in our hands. They can help us flexibly extract the required content from the database and present it in a variety of ways.

archiveListTag: The conductor of the content list.

archiveListThe tag is the core tag in Anqi CMS template, used to obtain and display document lists.No matter whether it is a blog post, product introduction, news information, or any document under a custom content model, it can be precisely filtered, sorted, and displayed according to the conditions we set.The strength of this tag lies in its flexibility and rich parameter options, allowing us to orchestrate all the content on the website like a conductor.

Let's delve into how to make use ofarchiveListtags to retrieve and display the document list under specified categories and models.

Precise positioning: Filter content through models and categories.

In AnQi CMS, a content model (Module) is like a 'mold' for content, defining the structure and fields of different types of content (for example, the 'article' model may have 'author', 'publish date' fields, and the 'product' model may have 'price', 'inventory' fields).And the category (Category) is a 'filing cabinet' for content, used for classifying and organizing content of the same type or across types.archiveListTag throughmoduleIdandcategoryIdThese two key parameters allow us to accurately lock in the target content.

  • Specify content model (moduleId)First, if your website has multiple content types, such as articles and products, you can go throughmoduleIdThe parameter specifies which content model's documents to retrieve. Each content model has a unique ID in the background.For example, if you want to retrieve all documents of the "Article" model, you would typically setmoduleId="1"(The specific ID should be configured according to your backend settings). This,archiveListit will only pull data related to articles, ignoring content from other models.

  • Filtering document categories (categoryId)After determining the content model, we often need to further refine it to one or more specific categories.categoryIdThe parameter allows you to specify one or more category IDs. You can pass a single ID, such ascategoryId="5"Retrieve all documents under the category with ID 5. If you need to retrieve documents from multiple categories, you can separate them with commas, for example,categoryId="5,8,12". A very practical skill is, when you wantarchiveListDo not automatically read the category ID of the current page, but get all category documents explicitly.categoryId="0"On the contrary, if you are on a category page and want to retrieve the documents under the category and its subcategories, it is usually not necessary to specifycategoryId,archiveListIt will intelligently read the category information on the current page.

Flexible Display: List Type and Display Quantity

archiveListTags provide various list display types to meet different page needs:

  • Non-paginated list (type="list")When you only need to display a small amount of content on a single page, such as the news headlines on the homepage, popular products in the sidebar, etc., you can usetype="list". In this mode, combinelimitParameters to control the number of documents displayed, for examplelimit="10"It will display the most recent 10 documents.limitIt also supports offset mode, such aslimit="2,10"which means starting from the 2nd document and retrieving a total of 10 documents.

  • Pagination list (type="page")For pages that need to display a large amount of content and require pagination navigation, such as article list pages and product display pages,type="page"it is an ideal choice. In this mode,archiveListBased on the current page number andlimitparameters (which are also used to define the number of items displayed per page) automatically handles pagination logic. When usingtype="page", it is usually paired withpaginationTags are used to generate pagination navigation bars, allowing users to easily browse documents on different pages.

  • Related documents (type="related")On the document detail page, you may want to display some recommended content related to the current document. At this time,type="related"It comes into play. It will intelligently recommend similar or related documents based on the keywords or associated settings of the current document.

Sorting and more control

In addition to the aforementioned core parameters,archiveListIt provides a series of parameters to further refine your content list:

  • Sorting method (order)You can sort the documents according to your needs. Common sorting methods include sorting by ID in reverse order (latest release), such asorder="id desc"; sorting by views in reverse order (most popular), such asorder="views desc"; as well as sorting by the custom sorting field in the background, such asorder="sort desc".

  • excluding specific categories(excludeCategoryId)If you need to get all documents under a certain model or category but want to exclude one or two categories, you can useexcludeCategoryIdparameters, for exampleexcludeCategoryId="3,7".

  • Including content with subcategories (child) childThe parameter is set to default.trueThis indicates that when fetching a specified category, it will also include the documents under its subcategories. If you only want to fetch the documents of the current category (without its subcategories), you can set it tochild=false.

  • Recommended attributes (flag)The AnQi CMS allows you to set various recommendation attributes for documents, such as headline[h], recommendation[c], etc. You can useflag="c"to retrieve documents with the 'recommendation' attribute.

Example Practice: Building a Dynamic Document List

To better understand the combination of these parameters, let's look at several common practical application scenarios.

Scenario one: Display the latest articles under a specific category

Assuming you have a 'Company News' category with ID 8, and you want to display the latest 5 news on the homepage:

<div>
    <h3>最新公司新闻</h3>
    <ul>
    {% archiveList latestNews with moduleId="1" categoryId="8" type="list" limit="5" order="id desc" %}
        {% for item in latestNews %}
        <li>
            <a href="{{item.Link}}">{{item.Title}}</a>
            <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </li>
        {% empty %}
        <li>暂无公司新闻。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

here,moduleId="1"Assumed to be an article model,categoryId="8"Specified the "company news" category,type="list"andlimit="5"Controlled the number of displayed items,order="id desc"Ensure that the content is up-to-date.

Scenario two: Display paginated product lists.

On a product display page, you may need to display all products page by page and provide pagination navigation:

<div class="product-list-container">
    {% archiveList products with moduleId="2" type="page" limit="12" order="views desc" %}
        {% for item in products %}
        <div class="product-item">
            <a href="{{item.Link}}">
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
                <h4>{{item.Title}}</h4>
                <p>浏览量: {{item.Views}}</p>
            </a>
        </div>
        {% empty %}
        <p>暂无产品信息。</p>
        {% endfor %}
    {% endarchiveList %}

    <div class="pagination-area">
        {% pagination pages with show="5" %}
            <a href="{{pages.FirstPage.Link}}">首页</a>
            {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
            {% for item in pages.Pages %}<a class="{% if item.IsCurrent %}active{% endif %}" href="{{item.Link}}">{{item.Name}}</a>{% endfor %}
            {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
            <a href="{{pages.LastPage.Link}}">尾页</a>
        {% endpagination %}
    </div>
</div>

In this example,moduleId="2"Assuming a product model,type="page"Pagination is enabled,limit="12"Define 12 products per page,order="views desc"Then sort in descending order by page views. The subsequentpaginationThe tag generates a complete pagination link.

Scenario three: complex multi-level classification and mixed document display

Suppose you need to display the top-level categories (such as "Solutions") and their subcategories on the homepage, and display the corresponding product documentation under each subcategory. If there are no subcategories, directly display the product documentation under the top-level category.

<div class="category-product-display">
    {% categoryList topCategories with moduleId="2" parentId="0" %} {# 获取顶级产品分类 #}
        {% for topCat in topCategories %}
        <section>
            <h2><a href="{{topCat.Link}}">{{topCat.Title}}</a></h2>
            <div class="sub-category-or-products">
                {% if topCat.HasChildren %} {# 如果有子分类,则显示子分类 #}
                    {% categoryList subCategories with parentId=topCat.Id %}
                        {% for subCat in subCategories %}
                        <div class="sub-category-block">
                            <h3><a href="{{subCat.Link}}">{{subCat.Title}}</a></h3>
                            <ul>
                                {% archiveList subCatProducts with type="list" categoryId=subCat.Id limit="4" %} {# 显示子分类下的产品 #}
                                    {% for product in subCatProducts %}
                                    <li><a href="{{product.Link}}">{{product.Title}}</a></li>
                                    {% empty %}
                                    <li>暂无产品。</li>
                                    {% endfor %}
                                {% endarchiveList %}
                            </ul>
                        </div>
                        {% endfor %}
                    {% endcategoryList %}
                {% else %} {# 如果没有子分类,直接显示顶级分类下的产品 #}
                    <ul>
                        {% archiveList topCatProducts with type="list" categoryId=topCat.Id limit="8" %}
                            {% for product in topCatProducts %}
                            <li><a href="{{product.Link}}">{{product.Title}}</a></li>
                            {% empty %}
                            <li>暂无产品。</li>
                            {% endfor %}
                        {% endarchiveList %}
                    </ul>
                {% endif %}
            </div>
        </section>
        {% endfor %}
    {% endcategoryList %}
</div>

This example shows.archiveListwithcategoryListNested tags are used and combined withifConditional judgment is used to handle different display logic for subcategories, greatly enhancing the dynamism and flexibility of the template.

Summary

archiveListTags are a powerful foundation for Anqi CMS content operation. By mastering its various parameters, and combining with other auxiliary tags such ascategoryDetail/paginationYou can easily build clear, powerful, and diverse web page structures.Apply these tags flexibly to help enhance the content organization and user browsing experience of your website.


Frequently Asked Questions (FAQ)

Q1: How do I know the ID or content model ID of a category?

A1:In the Anqi CMS backend, you can easily find these IDs. ForCategory IDEnter "Content Management" -> "Document Category", where the ID of each category is usually displayed next to the name in the category list, or you can click "Edit" to enter the detail page to see it as well. ForContent model IDEnter "Content Management" -> "Content Model", the ID of each model will also be displayed next to its name in the model list. These IDs are used in the template.moduleIdandcategoryIdThe basis when parameterizing.

Q2:type="list"andtype="page"While usingarchiveListWhat are the core differences when labeling?

A2:The main difference is whether pagination logic is handled.type="list"This is mainly used to get a fixed number of document lists without involving pagination. You need to specify the number of documents to display through thelimitparameter. If the number of documents exceedslimitThe redundant documents will not be displayed, and there will be no pagination navigation.type="page"It is used to obtain a paginated list of documents. It automatically calculates and displays the documents of the current page based on the current URL parameters (such as page number) and provides the total number of pages, the current page

Related articles

How does the `pageDetail` tag display the title, content, and thumbnail of a single page in AnQiCMS?

AnQiCMS provides an efficient way to manage independent pages, such as "About Us", "Contact Information", and so on.These pages usually have independent titles, content, and images, which need to be presented accurately in the front-end template.The `pageDetail` tag is the core tool designed by AnQi CMS to achieve this purpose, allowing us to easily extract and display the detailed information of a single page from the background database.Understanding the `pageDetail` tag: The core of single page content display In AnQiCMS

2025-11-08

How to get and display the list of all single pages of AnQiCMS using the `pageList` tag?

In Anqi CMS, a single page is a very flexible content form that does not rely on complex classification or model structures. It is often used to publish independent and relatively fixed pages such as "About Us", "Contact Information", and "Service Introduction".These pages are characterized by independent content, usually requiring only one page to carry their information.When you need to display a list of single pages at specific locations on a website, such as the bottom navigation, sidebar, or a special topic page, Anqi CMS provides a dedicated `pageList` tag to make this operation simple and intuitive.###

2025-11-08

How does the `categoryDetail` tag display the specific category details of AnQiCMS, such as the introduction or Banner image?

In Anqi CMS template development, effectively displaying detailed category information is the key to improving website user experience and SEO performance.`categoryDetail` tag is born for this, it allows us to flexibly obtain and present various information of specific categories, from basic introduction text to visually stunning Banner images, it can easily handle.### Core Function Analysis: `categoryDetail` Tag Overview The `categoryDetail` tag is mainly used to obtain detailed data for a single category

2025-11-08

How to retrieve and display the list of AnQiCMS articles or product categories using the `categoryList` tag?

Build a feature-rich, content-packed website in AnQiCMS, categories are an indispensable part of organizing content.Whether it is to display articles, products, services, or build navigation menus, a clear classification structure can greatly enhance the user experience and maintainability of the website.Today, let's delve deeply into a very practical and flexible tag in AnQiCMS——`categoryList`, which can help you easily obtain and display a list of articles or product categories.The `categoryList` tag is a powerful tool in the AnQiCMS template engine

2025-11-08

How to display AnQiCMS articles with the `archiveDetail` tag?

When building rich web pages in AnQiCMS, the `archiveDetail` tag is undoubtedly the core tool for displaying article detail pages.It can flexibly obtain and present all the detailed information of articles or products, helping website operators easily create detail pages that match the brand image and user experience.

2025-11-08

How to customize the display layout of the article detail page in AnQiCMS?

In website operation, the article detail page is like the 'face' of the content, it not only carries the core information, but is also a key touchpoint for users to understand deeply and resonate.A well-designed, logically laid out detail page that highlights the value of the content, can significantly enhance the user's reading experience, effectively convey information, and even promote further interaction or conversion.AnQi CMS understands its importance and therefore provides highly flexible and customizable features, allowing us to easily create exclusive article detail pages with unique styles.

2025-11-08

How to achieve multi-language content switching and display in AnQi CMS?

Under the wave of globalization content marketing, website support for multiple languages has become an indispensable function.AnQiCMS (AnQiCMS) understands this need and provides a flexible multilingual solution to help us easily present content to users in different languages.This article will discuss in detail how to implement multi-language content switching and display in Anqi CMS.### Distinguishing System Language and Content Language Before delving deeper, we first need to clarify the concepts of two types of "languages" in Anqi CMS: 1. **System Backend Language Pack:**

2025-11-08

How to take advantage of the pseudo-static function of Anqi CMS to optimize URL display for SEO?

In website operations, a clear and friendly website address (URL) not only improves user experience, but is also an indispensable part of search engine optimization (SEO).The original dynamic URL often contains complex parameters and symbols, which is not very friendly to search engine spiders and user understanding.The pseudo-static feature is exactly to convert these complex dynamic URLs into concise, readable, and static page-like URLs, thus optimizing the website's performance at both the visual and technical levels.

2025-11-08