How to retrieve and display a list of articles under a specific category (or multiple categories) in AnQiCMS?

Calendar 👁️ 70

In AnQiCMS, flexibly displaying website content is the key to improving user experience and website functionality.Whether you are operating a corporate website, a personal blog, or a marketing site, you often encounter the need to display a list of the latest articles, popular products, or multiple related category content under a specific category on a certain page.AnQiCMS's powerful template tag system, especiallyarchiveListLabel, can help you easily achieve this goal.

AnQiCMS with its efficient architecture based on the Go language and rich feature set provides solid support for content management.Its template engine syntax is concise and efficient, similar to the style of Django, allowing you to achieve complex content display logic through simple tag combinations, even if you do not have a deep background in development.

Let's explore together how to obtain and elegantly display the list of articles under a specific category or multiple categories on your AnQiCMS site.

Get to know the core tools:archiveListTag

To obtain the list of articles,archiveListIs the label you need to master first. It is very flexible, able to filter and sort articles according to various conditions. Its basic usage form is in{% archiveList 变量名 with 参数 %}and{% endarchiveList %}between, throughfora loop to iterate over the obtained article data.

For example, you want to get a list of articles under a category, the most critical parameter iscategoryId. This parameter allows you to specify one or more category IDs to precisely control which categories of articles are displayed.

Get the list of articles under a single category.

Assuming you have a "Company News" category with ID 1. To display the latest articles under this category on the page, you can write the template code like this:

<section class="latest-news">
    <h2>公司新闻</h2>
    <ul>
        {% archiveList articles with categoryId="1" limit="5" order="id desc" %}
            {% for item in articles %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        <h3>{{ item.Title }}</h3>
                        <p>{{ item.Description|truncatechars:100 }}</p>
                        <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    </a>
                </li>
            {% empty %}
                <li>当前分类下没有找到任何文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</section>

This code first declares a variable named:articlesThe variable is used to store the query results.categoryId="1"Specified to retrieve articles under the category with ID 1,limit="5"Limited to displaying only the latest 5 articles,order="id desc"and ensure that these articles are sorted in descending order by ID (i.e., the most recent published).forThe loop will iterate overarticleseach article,item.Link/item.Title/item.Descriptionwhich can help you display the basic information of the article. If there are no articles under this category,{% empty %}the content within the tag will be displayed.

Get articles under multiple categories

If you need to display articles from the 'Company News' (ID: 1), 'Industry Dynamics' (ID: 2), and 'Tech Sharing' (ID: 3) categories mixed on a page, categoryIdThe parameter is also supported. You only need to separate multiple category IDs with an English comma,and you can do so.

<section class="mixed-articles">
    <h2>精选文章</h2>
    <ul>
        {% archiveList articles with categoryId="1,2,3" limit="10" order="views desc" %}
            {% for item in articles %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        <h4>{{ item.Title }}</h4>
                        <!-- 在这里,我们可以获取并显示文章所属分类的名称 -->
                        <span class="category-name">分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                        <span>浏览量:{{ item.Views }}</span>
                    </a>
                </li>
            {% empty %}
                <li>没有找到任何精选文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</section>

In this example,categoryId="1,2,3"Tell the system to look for articles in these three categories. We will alsoorderchange the parameter toviews descSo the list will be sorted from high to low according to the article's viewing volume, helping you display popular content.

It is worth mentioning that inforWithin the loop, we also used{% categoryDetail with name="Title" id=item.CategoryId %}. This trick allows you to display the name of the category of each article next to it, greatly enhancing the navigation and user experience of the content.item.CategoryIdDynamically provides the current article's category ID,categoryDetailThe tag then retrieves the category name based on this ID.

Deep customization and pagination display

In addition to basic category filtering,archiveListThe tag also provides more flexible parameters, making your article list more dynamic.

  • moduleIdIf you define multiple content models (such as "article model" and "product model") in the AnQiCMS background, you canmoduleId="1"(usually 1 represents the article model) to specify which model's content you want to retrieve.
  • limit: Controls the number of articles displayed. For examplelimit="10"Display 10 articles, or you can also use the offset mode, such aslimit="2,10"Indicates starting from the 3rd article and displaying 10 articles.
  • order: Defines the sorting method of articles, excluding.id desc(Latest) andviews desc(Hot), you can also useorder="sort desc"(Custom sorting in the background) and others.
  • flag: Filter articles based on the recommended attributes set in the background of the article (such as headline[h], recommendation[c], etc.). For exampleflag="c"Only show articles marked as 'recommended'.
  • type="page"withpaginationCombined use of tagsWhen the number of articles is large and needs to be displayed in pages,archiveListoftypethe parameter topageThen you can usepaginationtags to generate pagination navigation.

This is an example of an article list that combines pagination features:

<section class="paginated-articles">
    <h3>最新动态(分页)</h3>
    {% archiveList articles with categoryId="4" moduleId="1" type="page" limit="8" order="id desc" %}
        {% for item in articles %}
            <article>
                <a href="{{ item.Link }}">
                    <img src="{{ item.Thumb }}" alt="{{ item.Title }}" onerror="this.style.display='none';">
                    <h5>{{ item.Title }}</h5>
                    <p>{{ item.Description|truncatechars:120 }}</p>
                    <small>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</small>
                </a>
            </article>
        {% empty %}
            <p>这个分类下暂时没有可显示的文章。</p>
        {% endfor %}

        {# 分页导航 #}
        <div class="pagination-nav">
            {% pagination pages with show="5" %}
                {% if pages.PrevPage %}
                    <a href="{{ pages.PrevPage.Link }}" class="page-link">上一页</a>
                {% endif %}
                {% for pageItem in pages.Pages %}
                    <a href="{{ pageItem.Link }}" class="page-link {% if pageItem.IsCurrent %}active{% endif %}">{{ pageItem.Name }}</a>
                {% endfor %}
                {% if pages.NextPage %}
                    <a href="{{ pages.NextPage.Link }}" class="page-link">下一页</a>
                {% endif %}
            {% endpagination %}
        </div>
    {% endarchiveList %}
</section>

In this example,type="page"It indicates that we need to display in pages,limit="8"Indicates that 8 articles are displayed per page.pagination pages with show="5"It will generate a pagination navigation bar that displays up to 5 page numbers, and provides links for "Previous page", "Next page", and each page number. You can according topageItem.IsCurrentTo determine the current page and add styles to it.

Summary

The template tag system of AnQiCMS provides great convenience to content operators. By using it flexibly,archiveList/categoryDetail/paginationTags, you can easily get and display the list of articles under a specific category (or multiple categories) at any location on the website, and sort, control the number, and display pagination according to your needs.These features not only help you better organize website content and improve SEO effects, but also bring visitors a smoother, more personalized browsing experience.


Frequently Asked Questions (FAQ)

Q1: I have set upcategoryIdandlimitWhy is the parameter, but the article list is not displayed or the number of displayed articles is incorrect? A1:Please check several aspects:

  • Is the category ID correct?Make sure the category ID you see in the background matches the ID used in the template.
  • Has the article been published?Articles with the status "Published" will be displayed on the front end. Drafts or scheduled articles that have not yet reached the scheduled time will not be displayed.
  • Is the number of articles sufficient?If you setlimit="5"But there are only 3 articles in this category, so only 3 will be displayed naturally.
  • Does the content model match?If you use bothmoduleIdPlease make sure that the ID matches your

Related articles

How to configure and display related article lists on the article detail page, and specify relevance rules (such as keywords or manual settings)?

How to make visitors easily find more related content after reading an excellent article on your website, continue to explore your website, which can not only significantly improve user experience, but also is a key strategy to optimize website SEO and reduce bounce rate.AnQiCMS (AnQiCMS) offers powerful and flexible features, allowing you to easily configure and display related article lists on the article detail page and specify relevance rules according to actual needs.Next, we will together learn how to achieve this goal in Anqi CMS.

2025-11-07

How to get and display the title and link of the previous and next articles on the article detail page?

It is crucial to provide a smooth user experience in the operation of our website.When a visitor finishes reading a rich article, they often want to follow the trail and continue browsing other content in the same category or related topics.In this case, it is particularly important to display the titles and links of the previous and next articles on the article detail page.

2025-11-07

How to implement the pagination display function of AnQiCMS article list, as well as how to customize the pagination style and logic?

In content operation, the pagination display of the article list is a basic and crucial function, which not only affects the user's browsing experience, but also is closely related to the performance and SEO performance of the website.AnQiCMS as an efficient and customizable content management system provides us with a flexible way to implement and beautify the pagination function of the article list.

2025-11-07

How to effectively retrieve and display a thumbnail, cover main image, or a collection of multiple images for an article?

In content operation, captivating images are an indispensable element to attract readers and enhance the quality of articles.AnQiCMS (AnQiCMS) understands this and provides a diverse and flexible set of features, whether it's for the thumbnails of article lists, the cover images on detailed pages, or rich multi-image collections, all can be easily obtained and displayed in the way you expect.How does AnQi CMS handle various images?In AnQi CMS, images are usually divided into several types to meet the display needs of different scenarios: * **Article Thumbnail (Thumb):**

2025-11-07

How to dynamically retrieve and display the content of custom model fields for an article in a template?

In AnQi CMS, the flexibility of website content is one of the key advantages for our content operation and website layout.By customizing content model fields, you can add unique properties for different types of content (such as articles, products), which can better reflect your business needs.But how can we dynamically present these carefully defined custom field contents in the front-end template of the website?This article will discuss this topic in detail, helping you fully utilize the powerful functions of AnQiCMS.

2025-11-07

How to retrieve and display the list of Tag tags and their corresponding links for an article?

In a website with increasingly rich content, how to effectively organize and present information is crucial.The Tag label (usually referred to as keywords or tags) not only helps users find related content quickly, but is also an indispensable part of Search Engine Optimization (SEO).AnQi CMS understands this point, providing users with a powerful and flexible tagging function, allowing you to easily add tags to articles and display these tags and their corresponding links in multiple forms on the website front end.

2025-11-07

How to retrieve and display the system global settings of AnQiCMS template, such as website name, Logo, filing number, and copyright information?

When building a website, some core information such as the website name, website logo, filing number, and copyright information are indispensable elements.These global settings not only help visitors quickly identify your brand, but also reflect the professionalism and compliance of the website.AnQiCMS provides a straightforward and flexible way to manage and present these system-level information in templates.Where can I set these global information?First, these important website information need to be unified configured in the AnQiCMS background.

2025-11-07

How to obtain and display the contact information of the website in AnQiCMS, such as phone, email, address, and social media links?

It is crucial to clearly display contact information when building and operating a website to establish user trust and provide customer support.AnQiCMS as an efficient content management system provides an intuitive way to manage and display this key information, whether it is traditional phone numbers, email addresses, or modern social media links, it can be easily realized. ### One, Back-end Configuration: Centralize Your Contact Information AnQiCMS has designed a centralized area for you to manage all website contact information in one place.

2025-11-07