How to get and display all articles under a specific category?

Calendar 👁️ 66

In website content management, effectively organizing and displaying articles is the key to improving user experience and the clarity of the website structure.AnQi CMS provides a powerful and flexible template tag feature, allowing you to easily retrieve and display all articles under a specific category.

Ensure the content structure is clear: the cornerstone of backend category settings

Before starting the operation on the template level, we must first ensure that the content structure of the background is clear and reasonable.The AnQi CMS category management feature is located under the "Content Management" module, where you can create and manage various article categories such as "Company News", "Industry Dynamics", or "Technical Tutorials" and so on.

When publishing or editing an article, you will find an option for 'Category', which is used to assign the article to a specific category.When you need to get a list of articles in a certain category, the system will filter according to the category information you specify in the background.

Core feature: usearchiveListTagging to retrieve article list

archiveListThe tag is a core tool in Anqi CMS template used to retrieve article lists. It is powerful and can accurately control the range and display style of the articles to be retrieved through various parameters.

To get articles under a specific category, the key is to usecategoryIdthis parameter. You can find the corresponding ID for each category in the "Content Management" -> "Document Category" section in the background.

In addition, you need to pay attention to several important parameters:

  • type:This parameter determines the form in which you want to display the list of articles.
    • is set tolist(type="list"When it is time, it will display according to the number you specify (vialimitParameters) list articles, commonly used for sidebar recommendations or homepage article blocks.
    • is set topage(type="page"When it creates pagination for the article list, which is very useful in scenarios where a large number of articles need to be displayed, such as category pages or search result pages.
  • limit:Used to control the number of articles displayed per page or per request. For example,limit="10"It will display 10 articles. It also supports offset mode, such as,limit="2,10"It means starting from the second article and getting 10 articles.
  • order:The order of the articles displayed is also important. You can set different sorting rules according to your needs:
    • order="id desc": Sort by article ID in descending order, which usually means the most recently published articles are at the top.
    • order="views desc": Sort by article views in descending order, with popular articles at the top.
    • order="sort desc": Sort by custom order in the backend, allowing you to manually adjust the article order.
  • moduleId:If you are managing multiple content models (such as having both "article model" and "product model"), make sure to specify the correct one.moduleIdThis can avoid confusion. The article model is usually set to 1 by default.

InarchiveListWithin the tag, you will use aforloop to iterate over each article obtained. Each article within the loop is represented by aitemvariable, you can use toitem.字段名In order to obtain various information about articles, such as:item.Title(Title),item.Link(Link),item.Description(Summary),item.Thumb(thumbnail),item.CreatedTime(Publishing time) anditem.Views(Views) and so on.

Build template code: from simple list to pagination display

After understanding these parameters, let's see how to apply them in the template.

Example 1: Get the latest 5 articles under a specific category (without pagination)

If you want to display several of the latest articles under a category on the homepage or sidebar, you can usetype="list". Suppose we want to get the latest 5 articles under the category1of 'Company News':

{# 获取ID为1的分类(例如“公司新闻”)下最新的5篇文章 #}
<div class="category-articles">
    <h2>公司新闻</h2>
    <ul>
    {% archiveList articles with categoryId="1" type="list" limit="5" order="id desc" %}
        {% for item in articles %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {# 如果有缩略图,则显示 #}
                    {% if item.Thumb %}
                        <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
                    {% endif %}
                    <h3>{{ item.Title }}</h3>
                    <p class="article-desc">{{ item.Description|truncatechars:80 }}</p> {# 截取简介,避免过长 #}
                    <span class="article-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </a>
            </li>
        {% empty %}
            {# 当该分类下没有文章时显示 #}
            <li>该分类下暂无文章。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

In this example, we also used{{ stampToDate(item.CreatedTime, "2006-01-02") }}a filter to format timestamps into readable dates.truncatechars:80which is used to truncate the article summary so that it does not exceed 80 characters.

Example two: Retrieve all articles under a specific category with pagination

When you need to display all articles under a category on the category details page, and provide pagination functionality,typethe parameter topage,and cooperatepaginationlabel usage

`twig {# Assuming we are on a category detail page, the current category ID will be automatically retrieved #} {# If you need to specify a category, you can manually add categoryId=“Your category ID” #} {% archiveList articles with type=“page” limit=“10” order=“id desc” %}

{# 列表头部可以显示当前分类的名称和描述 #}
<div class="category-header">
    <h1>{% categoryDetail with name="Title" %}</h1>
    <p>{% categoryDetail with name="Description" %}</p>
</div>

<div class="articles-list">
    {% for item in articles %}
        <div class="article-card">
            <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
            {% if item.Thumb %}
                <a href="{{ item.Link }}"><img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-card-thumb"></a>
            {% endif %}
            <p>{{ item.Description }}</p>
            <div class="article-meta">
                <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                <span>浏览量:{{ item.Views }}</span>
            </div>
        </div>
    {% empty %}
        <p>该分类下暂无文章。</p>
    {%

Related articles

How to display the latest articles or product lists on the website?

In Anqi CMS, it is an important aspect to manage and display website content, especially to allow visitors to see the latest published articles or product dynamics, which is crucial for enhancing user experience and website vitality.A dynamically updated website can not only attract users to continue visiting, but also is very beneficial for search engine optimization (SEO).AnQi CMS provides a powerful and flexible tag system, allowing us to easily meet this requirement.### Core Tool: `archiveList` Tag The most core tool to display the latest articles or product lists on any page of the AnQi CMS website is

2025-11-09

How to use the anchor text feature of AnQiCMS to improve the display effect of internal links?

The internal links of the website are like a complex maze, guiding users and search engines through various pages.And the anchor text, which is the 'road sign' on this map, directly determines the efficiency and user experience of navigation.A clear and relevant anchor text not only enhances user click-through intention but is also an important basis for search engines to understand page content and evaluate page authority.AnQiCMS as an efficient content management system is well-versed in this, providing a strong and flexible anchor text feature to help us easily improve the display effect of internal links.###

2025-11-09

What is the role of Sitemap and Robots.txt in content visibility?

Enhancing website content visibility: The key role of Sitemap and Robots.txt in Anqi CMS Making website content visible to more people is the core goal of every content operator.In a world of information overload on the Internet, search engines are the bridge for users to discover content, and in this competition to gain the attention of search engines, Sitemap (site map) and Robots.txt (crawler protocol file) are two indispensable tools.For users of AnQi CMS, the powerful functions of these two tools have been integrated into the system

2025-11-09

How to set independent SEO titles and descriptions for articles, categories, and tags?

In website operation, it is crucial to make your content stand out in search engines.AnQiCMS (AnQiCMS) is well-versed in this field, providing users with flexible and powerful SEO settings, allowing you to customize independent SEO titles and descriptions for each article, category, and even each tag.This not only helps to improve the visibility of the website in search results, but also accurately attracts the target audience, thereby increasing click-through rates and website traffic.Next, we will discuss in detail how to set exclusive SEO information for different types of content entities in Anqi CMS

2025-11-09

How to display the detailed content page of articles or products?

In Anqi CMS, the display of article or product detailed content pages is the core link of website content operation.A well-designed, comprehensive detail page that can effectively convey content value and enhance user experience and search engine friendliness.Strong and flexible tool set provided by AnQi CMS, allowing us to easily achieve these goals. ### The Foundation of Content: Content Model and Template Files In Anqi CMS, all articles and products are unified as "content" (archive). They can exhibit different forms

2025-11-09

How to display a list of recommended articles related to the current article?

In website operation, recommending relevant articles to readers is an important strategy to enhance user experience, prolong user stay time, and optimize SEO.After a reader finishes reading an article, if they can immediately see highly relevant recommendations related to the current content, it will undoubtedly greatly increase their interest in continuing to explore the website.AnQi CMS understands this need and provides powerful and flexible features to help users easily achieve this goal.### AnqiCMS's "Related Documents" feature One of the core strengths of AnqiCMS lies in its powerful content management and template tag system

2025-11-09

How to retrieve and display the list of all categories on the website?

In Anqi CMS, the website category list is the foundation for building clear navigation, enhancing user experience, and optimizing search engine rankings.Whether it is to establish a classification system for articles, products, or other content models, AnQiCMS provides flexible and powerful tools to easily obtain and display these classifications.One of the core concepts of AnQiCMS is to make content management efficient.It organizes the content into different "content models", such as common article models and product models.Each content model can have an independent classification system. Understanding this is the first step to obtaining the classification list.

2025-11-09

How to display subcategories on the category page, or show the article list when there are no subcategories?

In website operation, the content display logic of category pages has an important impact on user experience and information architecture.We often encounter such needs: when there are subcategories under a category, it is preferred to display these subcategories to facilitate users in navigating more finely;And if the category does not have subcategories, then directly display the list of articles under the category, to avoid the page content being empty or the navigation level being too deep.AnQiCMS (AnQiCMS) provides flexible template tags that can easily achieve this dynamic display effect.### Understand the dynamic display logic of the category page To implement the intelligent display of the category page

2025-11-09