How to display only articles of specific categories in the article list?

Calendar 👁️ 74

When managing website content in Anqi CMS, we often need to flexibly control the display of article lists, for example, only displaying articles under specific categories on a particular page.This not only helps to organize the content of the website accurately, but also greatly improves the browsing experience of visitors, helping them find the information they are interested in faster.AnQi CMS provides powerful template tag functions, making this requirement simple and intuitive.

The core of achieving this goal lies in Anqi CMS'sarchiveListTemplate tag. This tag is used to obtain the article list from the database, which is the '万能钥匙'. By configuring different parameters, we can accurately filter out the desired content.

UnderstandarchiveListthe critical parameters

InarchiveListThere are two crucial parameters in the tag that are used to filter articles of a specific category:

  • moduleIdThis parameter is used to specify the content model you want to retrieve for the article.In Anqi CMS, articles, products, and so on all belong to different content models.The ID of the 'Article Model' is 1, the ID of the 'Product Model' is 2, you can view or customize it in the 'Content Management' -> 'Content Model' on the backend.Ensure the specified is correctmoduleIdis the first step to obtaining the correct list of articles.
  • categoryIdThis is the key parameter directly specifying the category of the article. By providing one or more category IDs, you can makearchiveListtags only return articles under these categories.

How to get the category ID?

In usecategoryIdBefore the parameter, you need to know the ID of the target category. There are several common methods to get the category ID:

  1. Obtained from the backend management interface:The most direct way is to log in to the Anqi CMS backend, go to 'Content Management' -> 'Document Categories'. Here, each category will clearly list its corresponding ID.
  2. Retrieve dynamically through template tags:If you are on a category detail page or its subpage and want to display articles of the current category, you can usecategoryDetailLabel to get the current category ID and then pass it toarchiveListFor example,{% categoryDetail with name="Id" %}You can directly output the current category ID.

Practical scenario: Accurate control of article list

MasteredmoduleIdandcategoryIdAfter parameters and how to obtain the category ID, we can meet various article list display requirements.

Firstly, assume that you want to display the latest articles under the specific category "Company News" in a block of the website.You need to find the 'Company News' category ID in the background first (for example, assuming its ID is 10), and the article model ID is usually 1.So, you can use it like this in the templatearchiveListTags:

{% archiveList newsArticles with moduleId="1" categoryId="10" limit="5" %}
    {% for article in newsArticles %}
        <div class="news-item">
            <h4><a href="{{ article.Link }}">{{ article.Title }}</a></h4>
            <p>{{ article.Description }}</p>
            <span>发布日期:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% else %}
        <p>暂无公司新闻。</p>
    {% endfor %}
{% endarchiveList %}

This code will get the article model(moduleId="1") under the category ID 10(categoryId="10"The latest 5 articles in the bracket.

Secondly, if you need to display articles from multiple specific categories in a list, such as 'Company News' (ID: 10) and 'Industry Dynamics' (ID: 12), you just need tocategoryIdComma-separated to separate these category IDs:

{% archiveList mixedArticles with moduleId="1" categoryId="10,12" limit="10" order="CreatedTime desc" %}
    {% for article in mixedArticles %}
        <div class="article-card">
            <h5><a href="{{ article.Link }}">{{ article.Title }}</a></h5>
            <small>分类: {% categoryDetail with name="Title" id=article.CategoryId %}</small>
            <span> | 日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
        </div>
    {% else %}
        <p>暂无相关文章。</p>
    {% endfor %}
{% endarchiveList %}

here,order="CreatedTime desc"Parameter used to sort articles by publish time in descending order to ensure the latest content is displayed.

Again, often we will build a page layout that displays content grouped by categories, such as displaying several category titles on the page, and then listing several articles under each title. This can be achieved by combiningcategoryListandarchiveListtags to implement:

{% categoryList mainCategories with moduleId="1" parentId="0" %} {# 获取文章模型下的所有顶级分类 #}
    {% for category in mainCategories %}
        <section class="category-block">
            <h2><a href="{{ category.Link }}">{{ category.Title }}</a></h2>
            <ul class="article-list">
                {% archiveList articlesInCategory with moduleId="1" categoryId=category.Id limit="3" %} {# 显示当前分类下的3篇文章 #}
                    {% for article in articlesInCategory %}
                        <li><a href="{{ article.Link }}">{{ article.Title }}</a></li>
                    {% endfor %}
                {% else %}
                    <li>该分类暂无文章。</li>
                {% endarchiveList %}
            </ul>
        </section>
    {% endfor %}
{% endcategoryList %}

In this example,categoryListTraversal of all top-level article categories, then for each category, nested thearchiveListUsecategory.IdParameters, dynamically retrieve and display the articles under the category.

Finally, if you want to display all articles under a specific content model but need to exclude one or more specific categories, such as not displaying articles from the category "Internal Announcement" (ID: 15), AnQi CMS also providesexcludeCategoryIdThe parameter meets this requirement:

{% archiveList allButInternal with moduleId="1" excludeCategoryId="15" limit="10" %}
    {% for article in allButInternal %}
        <div class="general-article-item">
            <h3><a href="{{ article.Link }}">{{ article.Title }}</a></h3>
            <span>分类:{% categoryDetail with name="Title" id=article.CategoryId %}</span>
        </div>
    {% else %}
        <p>暂无文章可显示。</p>
    {% endfor %}
{% endarchiveList %}

This line of code retrieves the content of all article models except the category with ID 15.

Tips and注意事项

In actual operation, please ensure that your template file conforms to the template naming and directory structure conventions of AnQi CMS, for example, category lists usually use{模型table}/list.htmlsuch naming format. At the same time,archiveListTags alsolimit(Limit the number of articles),order(Sorting methods, such as by publication time, views, etc.) as well astype(List type, such aslistUsed for simple lists,pageUsed for pagination lists) and more parameters, which can help you further refine the display logic of the article list.Use these parameters reasonably to make your website content more organized and professional.

By these flexible label combinations and parameter configurations, Anqi CMS allows you to easily handle the content of the website's articles, whether it is creating special pages, displaying recommended content, or building complex classification navigation, you can do it with ease.


Frequently Asked Questions (FAQ)

  1. How to determine the article model?moduleIdare?In most cases, the ID of the "Article Model" built into Anqi CMS is 1, and the ID of the "Product Model" is 2.You can log in to the backend management interface, go to "Content Management"->"Content Model", where you can clearly see each content model and its corresponding ID.If you customize a new content model, its ID will also be displayed here.

  2. Do I need to make additional settings to display the articles of the current category and all its subcategories in the article list?No additional settings are required.archiveListThe tag supports fetching articles of the specified category and all its subcategories by default. That is to say, when you setcategoryIdWhen a category ID is passed as a parameter, it will automatically include all articles under the category. It is only necessary to use it when you explicitly do not want to include articles from subcategories.child="false"Parameter.

  3. Why did I setcategoryIdAfter, the article list is still empty or displays incorrectly?This may be caused by several reasons. First, please checkmoduleIdandcategoryIdAre they correct, make sure they match the actual content model and category IDs on the backend.Next, confirm that there is indeed an article published (not a draft or in the recycle bin) under this category.Also, checklimitwhether the parameters are set correctly?

Related articles

Does AnQiCMS support displaying different detail page styles based on different content models?

In website operation, we often encounter such needs: different types of content, even on the same website, also need to have completely different display styles.For example, a product detail page of an e-commerce website needs to highlight product images, prices, inventory information, etc., while the blog article detail page may focus more on the reading experience, author information, and publication date.This ability to customize the style of detail pages based on content type (also known as content model) is crucial for improving user experience and content professionalism.Then, while using AnQiCMS

2025-11-09

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

AnQiCMS provides a very flexible and powerful content management system, allowing us to easily customize the display layout of article detail pages.In order to enhance user experience, optimize SEO, or better showcase the brand characteristics, AnQiCMS can help us achieve these goals through its intuitive template system and rich tag features.How can we proceed specifically? We can delve into these aspects step by step.### 1. Understanding AnQiCMS template mechanism First

2025-11-09

How to display or customize the error pages (such as 404, 500) and shutdown notifications of a website?

In the operation of the website, visitors may encounter pages that cannot be found for various reasons or temporary issues with the server, and may even be unable to access the website during maintenance and upgrades.In these situations, a well-designed error page (such as 404, 500) and a friendly shutdown prompt can not only greatly improve user experience but also maintain the professional image of the website to a certain extent and search engine optimization (SEO).AnQi CMS is an efficient content management system that provides a flexible way to display and customize these important pages.###

2025-11-09

How to display the list of dynamic Banner images configured in the website?

The website's banner area, like a dynamic promotional window, its visual appeal and content delivery efficiency directly affect the first impression of visitors to the website.A well-designed Banner that can quickly capture the user's attention and effectively showcase the brand image, latest activities, or core products.In AnQiCMS (AnQi CMS), by utilizing its powerful content management features, you can easily configure and display a dynamic banner image list, keeping your website fresh and attractive.###

2025-11-09

How to configure AnQiCMS to enable lazy loading of images on the page?

In today's rich network world, the speed of website loading is of great importance to user experience and search engine optimization (SEO).Especially when a page contains a large number of images, how to effectively manage the loading of these images, avoid the lag caused by loading all resources at once, has become a focus of many website operators.The Lazy Load (Lazy Load) technology is the tool to solve this problem, it allows images to be loaded only when the user is about to see them, thus significantly improving page performance.AnQiCMS as a high-performance content management system

2025-11-09

How to use template tags to dynamically display the associated Tag list in article content?

How can we make users see the related keywords or topic list in an article at a glance while browsing, so as to guide them to discover more interesting content and thus improve user experience and website stickiness, which is an important link.AnQiCMS (AnQiCMS) provides powerful template tag features, allowing you to easily display related Tag lists dynamically in article content, which is both beautiful and practical.**Understanding the Tag Function of AnQi CMS** Tags in AnQi CMS are not just simple classifications of articles

2025-11-09

How does the multi-site feature of AnQiCMS affect the display and switching of front-end content?

When using a website content management system, the multi-site feature has always been a topic of concern.It not only concerns the operational efficiency, but also directly affects the organization, display of website content, and the smooth switching experience of users between different sites.For AnQiCMS users, its powerful multi-site feature is the tool to solve these challenges.Let's delve into how the multi-site feature of AnQiCMS affects the display and switching of front-end content.One of the design初衷 of AnQiCMS is to meet the needs of users managing multiple brands, sub-sites, or multilingual content

2025-11-09

How to use AnQiCMS's pseudo-static rules to optimize the display structure of article URLs to improve SEO?

In website operation, the URL is not only the entrance for users to access content, but also an important basis for search engines to understand and crawl website content.A clear and semantically friendly URL can significantly improve user experience and website performance in search engines.One of the key factors to achieve this goal is to skillfully use pseudo-static technology.AnQiCMS as a high-efficiency and customizable content management system, fully considers the needs of SEO optimization, and provides powerful and flexible pseudo-static rule configuration functions. Today

2025-11-09