How to get the list of articles under a specified category in AnQiCMS?

Calendar 👁️ 65

Easily get the list of articles under a specified category in AnQiCMS

As an experienced website operations expert, I fully understand the core value of a content management system (CMS) lies in its ability to organize and present content.Among many functions, how to efficiently extract and display articles from a specific category is an indispensable part of the daily work of website operators.Today, let's delve into how AnQiCMS can help you achieve this goal, making technical details intuitive and easy to understand.

AnQiCMS as an enterprise-level content management system based on the Go language, with its concise and efficient architecture, provides us with a flexible and powerful content display mechanism.Among them, obtaining the list of articles under a specified category is achieved through its carefully designed template tags.

Understand the Core:archiveListTemplate Tag

In AnQiCMS, to get the list of articles under a specified category, we mainly rely on a powerful template tag:archiveList. This tag is like an intelligent filter that can accurately find the required articles from a vast content library based on the conditions provided and present them.

When you need to display articles of a specific category in the AnQiCMS template file, the first thing that comes to mind isarchiveList. Its most common usage is withcategoryIdCombine parameters to clearly tell the system which category of articles you want to retrieve. For example, if you have a category ID of 10 for the "Company News" section, you can usecategoryId="10"Specify this category.

Let's look at a basic structure:

{% archiveList archives with categoryId="10" limit="5" order="id desc" %}
    {% for item in archives %}
        <!-- 在这里展示每篇文章的详细信息 -->
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description }}</p>
        <p>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>
        <hr>
    {% empty %}
        <p>该分类下暂无文章。</p>
    {% endfor %}
{% endarchiveList %}

In this code block,archivesIs a variable name we define to storearchiveListThe collection of article data returned by the tag.limit="5"Tell the system to only display the latest 5 articles, andorder="id desc"Then ensure that these articles are sorted in descending order by ID, that is, the most recently published articles come first.{% for item in archives %}The loop then iterates over these articles,itemThe variable represents the current article being traversed, you canitem.Title/item.Link/item.Descriptionaccess the various attributes of the article in this way. If there are no articles under the category,{% empty %}the content in the block will be displayed.

Wisdom in dynamically acquiring category ID

In actual operation, the classification ID is often not fixed.For example, when you visit a category page, you may want to automatically display the articles under that category instead of manually entering the category ID.AnQiCMS also provides an elegant solution.

You can usecategoryDetailTag to dynamically acquire the category information of the current page, including its ID.

{# 假设当前页面是一个分类列表页 #}
{% categoryDetail currentCategory with name="Id" %}
{% archiveList archives with categoryId=currentCategory limit="10" order="views desc" %}
    {% for item in archives %}
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>浏览量:{{ item.Views }}</p>
    {% endfor %}
{% endarchiveList %}

Here, currentCategoryThe variable stores the category ID of the current page and passes it toarchiveListofcategoryIdParameters. This way, no matter which category page the user visits, the articles under that category will be displayed automatically.

Deep Dive: Flexible Application of More Parameters.

archiveListThe power of the label goes far beyond this, it also provides various parameters to meet more complex needs:

  • moduleId: AnQiCMS supports flexible content models (such as articles, products, etc.). If you only want to retrieve articles under a specific content model, you can setmoduleIdFor example,moduleId="1"It usually represents the article model.
  • child: By default,archiveListit will retrieve articles under the specified category and all its subcategories. If you only want to display articles under the current category and not include the content of subcategories, you can setchild=false.
  • typeThis parameter is very critical,type="list"indicating to retrieve a fixed number of article lists, whiletype="page"it is used to generate paginated article lists, usually withpaginationUse tags together to enable the "previous page/next page" navigation function.
  • flag: If your article has set recommendation attributes (such as头条[h], 推荐[c] etc.), you canflag="c"filter articles with specific recommendation attributes.
  • q: Use the search page toqspecify search keywords,archiveListwhich will return articles with the specified keyword in the title.

Example: CombinecategoryListto display articles from multiple categories in sequence.

A common requirement is to display multiple categories and the latest articles under them on the homepage or some aggregation page. This can be achieved by nestingcategoryListandarchiveListtags to implement:

{% categoryList categories with moduleId="1" parentId="0" %} {# 获取所有顶级分类 #}
    {% for category in categories %}
        <section>
            <h2><a href="{{ category.Link }}">{{ category.Title }}</a></h2>
            <ul>
                {% archiveList articlesInCategory with categoryId=category.Id limit="5" order="id desc" %}
                    {% for article in articlesInCategory %}
                        <li>
                            <a href="{{ article.Link }}">{{ article.Title }}</a>
                            <span>({{ stampToDate(article.CreatedTime, "01-02") }})</span>
                        </li>
                    {% empty %}
                        <li>此分类下暂无内容。</li>
                    {% endfor %}
                {% endarchiveList %}
            </ul>
        </section>
    {% endfor %}
{% endcategoryList %}

This code first retrieves all top-level article categories, and then for each category, retrieves the 5 latest articles under it. BystampToDateFilter, we can also format the publication time of the article into a concise 'month-day' format.

Optimization of template file selection

AnQiCMS is also very flexible in template design, supporting the use of different templates for different categories. For example, you can create{模型table}/list-{分类ID}.htmlThis template file allows a specific category to have a unique list display style. This is very helpful for achieving personalized content layout and SEO optimization.

By using these tags and techniques, you can effortlessly obtain and display the article list under the specified category in AnQiCMS, whether it is a simple list display or a complex aggregation page, you can easily deal with it.Effectively utilize these tools will greatly enhance the management efficiency and user experience of your website content.


Frequently Asked Questions (FAQ)

Q1: How do I get all articles under all categories?

If you want to get all articles under all categories on the website instead of specifying a single category, you can usearchiveListOmitting the labelcategoryIdParameters, AnQiCMS will default to returning all articles. Of course, for performance considerations, you would usually cooperate withlimitParameters to limit the number of articles returned, or usetype="page"andpaginationTags are displayed by pagination.

Q2: If my articles have different content models (such as 'news' and 'product'), how can I retrieve them separately?

AnQiCMS supports custom content models, each model has a uniquemoduleId. When you usearchiveListtags, you can go throughmoduleId="X"Specify the article of the content model you want to retrieve,Xis the ID corresponding to the content model. For example, if the article modelmoduleIdis 1, the product modelmoduleIdis 2, you can set upmoduleId="1"Get only the articles.

Q3: I want to display the sub-categories of the category on the category list page at the same time, and list the articles under the sub-categories. Can this be done?

It can be done. You can use nestingcategoryListTags to achieve multi-level classification display. In the outer layercategoryListIn the loop, determine if the current category has subcategories (item.HasChildren), if so, use another onecategoryListTag retrieval and traversal of its subcategories; if there are no subcategories, or if you want to display articles below the subcategories, you can embed it in the corresponding looparchiveListthe tag and use it.categoryIdThe parameter is set to the ID of the current category.In the document, the example of

Related articles

Unveiling AnQi CMS: How Markdown content is beautifully presented on your website?

AnQi CMS is an efficient content management system that knows well the pursuit of convenience by content creators.Markdown is a lightweight markup language that is favored by content editors for its concise, easy-to-learn, and clear formatting features.How can we ensure that the wonderful content you write in Markdown in Anqi CMS can be perfectly converted into browser-readable HTML and displayed on the front-end page without any loss?

2025-11-06

How to call custom document fields (such as author, price) and display them in AnQi CMS?

AnQi CMS offers powerful content management capabilities with its excellent flexibility and customizability to website operators.In the daily operation of websites, we often encounter situations where standard fields (such as titles, content, and publication time) cannot fully meet the needs of specific content display.At this moment, custom document fields have become our powerful assistants, for example, adding "author" information to an article, or supplementing "price" attributes to a product, and so on.How can we flexibly call these custom fields and display them on the website page in Anqi CMS today?

2025-11-06

How to obtain all the details of the category owned by the document details page?

How to retrieve all detailed information of the category owned by the document detail page of Anqi CMS?In website content operations, the document detail page is not just for displaying articles or products, it often needs to establish a connection with a broader content system, such as displaying detailed information about its category.This not only enhances the user experience, guides users to discover more related content, but also helps improve the internal link structure and SEO performance of the website.As an experienced website operation expert, I deeply understand the strength and flexibility of AnQiCMS (AnQiCMS) in dealing with such needs.

2025-11-06

How to format the display of the release and update time of AnQiCMS documents?

As an experienced website operations expert, I am well aware that the accuracy and readability of time in content display are crucial for user experience and Search Engine Optimization (SEO).AnQiCMS as an efficient and flexible content management system provides a very convenient way to control the display format of the publication and update time of articles.This article will focus on how AnQiCMS formats and displays the publication and update times of documents, and will explain the secrets and practical skills in detail.

2025-11-06

How to implement pagination and page number display for article lists in AnQi CMS?

As an experienced website operations expert, I am well aware of the crucial role of a powerful and easy-to-use content management system for the success of a website.AnQiCMS (AnQiCMS) boasts a high-performance architecture based on the Go language and flexible template mechanism, providing an excellent experience in content publishing and management.Among them, efficiently displaying a large amount of content, especially implementing the pagination function of the article list, is an indispensable factor in improving user experience and website SEO performance.Today, let's delve deeply into how AnQi CMS cleverly implements this feature and demonstrates friendly page navigation.--- ##

2025-11-06

How to filter and display the document list based on recommended properties (Flag)?

As an experienced website operations expert, I know that the powerful function of the Content Management System (CMS) lies in its flexibility and ease of use.In AnQiCMS (AnQiCMS), the 'recommended attribute' (Flag) of the document is such a seemingly simple feature, which can actually greatly improve the efficiency of content operation and the diversity of website display.Today, let's delve into how to cleverly use recommendation attributes to achieve precise filtering and display of document lists.

2025-11-06

How to sort the document list by publication time or views?

In the world of website operation, the organization and presentation of content directly affects the user experience and the efficiency of information transmission.AnQiCMS (AnQiCMS) as an efficient content management system, fully understands the importance of this requirement, and therefore provides powerful and flexible options for sorting document lists, allowing you to easily control the display priority of content according to different operation goals.Today, let's delve into how to sort document lists in Anqi CMS using publication time or views.

2025-11-06

How to exclude certain specific categories of articles from the AnQiCMS document list?

During the operation of the website, we often need to manage and display content in a fine-grained manner.For example, we may wish to hide certain internal announcements, specific promotional content, or some draft category articles that are not suitable for external display when recommending articles on the homepage.AnQiCMS (AnQiCMS) is a powerful content management system that fully considers such needs and provides a simple and flexible way to achieve this - by specifying exclusion parameters in the document list tag.This article will delve into how to exclude certain categories of articles from the document list in AnQiCMS

2025-11-06