How to aggregate and display a list of selected articles under multiple categories on a single page?

Calendar 👁️ 70

In website operation, we often encounter such needs: on the homepage or some special page, we can display "精选" articles from different categories, which can enrich the page content and guide users to discover more interesting information.AnQiCMS (AnQiCMS) provides very flexible and powerful features, allowing us to easily achieve this goal without complex programming knowledge.

To aggregate and display a list of selected articles under multiple categories on a single page, we mainly use the Anqi CMS's“Recommended Attributes”function as well as“Document List Tags”(archiveList).

Understand the selection mechanism and content organization of AnQi CMS

In AnQi CMS, the selected status of content is through theRecommended attribute (Flag)To be defined.When editing an article, you can select various attributes in the "Recommendation Attributes" option, such as "Top [h]", "Recommended [c]", "Slider [f]", and so on.Here, 'recommended[c]' is a very suitable attribute for marking 'selected' articles.You just need to check the corresponding "recommended" attribute when publishing or editing articles in the background to mark it as featured content.

At the same time, articles will belong to specific categories and content models.To aggregate articles under multiple categories, we need to understand the IDs of these categories.You can view and manage your categories in the Anqi CMS backend under 'Content Management' -> 'Document Category', and each category will have a unique ID.

Plan one: Display the selected article list under each category one by one

If you want the page structure to be clear, for example, "Category A SelectionThis method helps users quickly locate high-quality content in specific categories.

First, wecategoryListuse tags to obtain the list of categories to be displayed, and then, inside the loop of each category,archiveListTag to get the selected articles under this category.

{# 假设我们要获取ID为1、2、3的分类,并逐个展示其下的精选文章 #}
{# 您可以在后台“内容管理”->“文档分类”中查看分类ID #}
{% categoryList targetCategories with moduleId="1" parentId="0" %} {# 获取所有顶级文章分类,moduleId=1通常代表文章模型 #}
    {% for category in targetCategories %}
        {# 仅展示您感兴趣的分类,例如ID为1,2,3的分类 #}
        {% if category.Id == 1 or category.Id == 2 or category.Id == 3 %}
            <div class="category-featured-section">
                <h3><a href="{{ category.Link }}">{{ category.Title }}</a> 下的精选文章</h3>
                <ul>
                    {# 使用archiveList获取当前分类(category.Id)下,推荐属性为'c'(精选)的文章,限制显示5篇,并按浏览量倒序排序 #}
                    {% archiveList featuredArticles with categoryId=category.Id flag="c" limit="5" order="views desc" %}
                        {% for article in featuredArticles %}
                            <li>
                                <a href="{{ article.Link }}">{{ article.Title }}</a>
                                <p>{{ article.Description|truncatechars:80 }}</p> {# 截取文章描述前80个字符 #}
                                <span>发布日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                            </li>
                        {% else %}
                            {# 如果当前分类下没有找到精选文章,显示此提示 #}
                            <li>当前分类暂无精选文章可供展示。</li>
                        {% endfor %}
                    {% endarchiveList %}
                </ul>
                <a href="{{ category.Link }}" class="view-more">查看更多 {{ category.Title }} 文章</a>
            </div>
        {% endif %}
    {% endfor %}
{% endcategoryList %}

In this code, we first go throughcategoryListGot the top-level article categories. While traversing these categories, we throughifThe condition judgment only processes those specific categories that we want to display (for example, ID 1, 2, 3). Then, within each target category, use it againarchiveListThe key point this time iscategoryId=category.Id(Make sure to retrieve the articles of the current category) andflag="c"(Filter out the selected articles).limitandorderParameters can help us control the display quantity and sorting method.

Plan two: Aggregate display of all selected articles in specified categories

If you want to display selected articles from different categories in a list without distinguishing the category affiliation and emphasize the 'selected' attribute of the content, then you can adopt this more direct aggregation method.

This implementation is more concise, using a direct one.archiveListTag it and it is.archiveListofcategoryIdThe parameter supports passing multiple category IDs separated by commas, which is the key to our aggregation of articles.

<div class="all-featured-articles-list">
    <h2>全站精选文章聚合</h2>
    <ul>
        {# 获取ID为1、2、3的分类下,推荐属性为'c'(精选)的文章,限制显示10篇,并按ID倒序(最新发布) #}
        {% archiveList aggregatedFeaturedArticles with categoryId="1,2,3" flag="c" limit="10" order="id desc" %}
            {% for article in aggregatedFeaturedArticles %}
                <li>
                    <a href="{{ article.Link }}">{{ article.Title }}</a>
                    <p class="article-meta">
                        {# 使用categoryDetail获取文章所属分类的名称,增强上下文信息 #}
                        <span class="article-category">所属分类: {% categoryDetail with name="Title" id=article.CategoryId %}</span>
                        <span class="article-date">发布日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                    </p>
                    <p>{{ article.Description|truncatechars:120 }}</p> {# 截取文章描述前120个字符 #}
                </li>
            {% else %}
                {# 如果没有找到任何精选文章,显示此提示 #}
                <li>目前暂无精选文章可供展示。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In this example,categoryId="1,2,3"LetarchiveListTags fetch articles from these three categories at once, andflag="c"ensuring that only articles marked as "recommended" are listed. We have also added an extracategoryDetailTags to display the category of each article, which is very useful in the aggregated list, allowing users to understand the source of the content.

Optimization and注意事项

  1. Template path:Make sure your template file is placed in/templateUnder the directory, and create the corresponding files according to the organization mode (folder organization or flattened) you choose. For example, if you aggregate and display on the homepage, it is usually inindex/index.htmlorindex.htmlAdd the above code.
  2. Style beautification:This code only provides the basic HTML structure.To make the page look more beautiful, you need to combine CSS for styling design.The template design of AnQi CMS is very flexible, you can freely add style files.
  3. The definition of 'Featured':Make sure to correctly set the 'Recommendation Attribute (Flag)' to the articles you want to display as 'Featured' in the background management.cIf the article does not set this attribute, it will not be

Related articles

How to display the links to the previous and next articles at the bottom of the article detail page?

In website content operation, improving user reading experience is a key link.After a reader has finished browsing an excellent article, if they can immediately see a link to the next related or sequential article, it will undoubtedly greatly increase the likelihood that they will continue to stay on the website.This design not only optimizes the user experience, helps guide users to delve deeper into the website's content, but also effectively reduces the bounce rate and enhances the website's SEO performance, allowing search engines to better understand the structure of your website's content.

2025-11-08

How to filter and display related article lists on the front page according to the specified category ID?

In Anqi CMS, it is actually very simple to filter and display a list of related articles on the front page according to the category ID!The AnQi CMS, with its efficient and flexible features, makes content management and display easy.No matter if you are running a corporate website, an industry information station, or a personal blog, you may encounter the need to display a list of articles according to a specific category.For example, display articles from a certain "Hot Recommendation" category on the homepage, or showcase specific "Product Cases" on a special topic page.Today, let's talk about how to accurately implement this function in the Anqi CMS front-end template.###

2025-11-08

How to implement user-friendly pagination navigation display for the article list?

The article list is the core display area of the website content, and its user experience directly affects the visitor's stay time and willingness to revisit.When the number of articles is large, a reasonable page navigation design is particularly important.AnQiCMS (AnQiCMS) provides powerful and flexible template tags to help us easily implement user-friendly article list pagination functions, making content management and display more efficient.

2025-11-08

How does AnQiCMS display the latest article list and its publication time on the front end?

In website operation, displaying the latest published content to visitors in a timely manner can not only effectively improve user experience but also enhance the activity of the website.AnQiCMS (AnQiCMS) provides an intuitive and powerful template tag feature, allowing you to easily display the latest article list and its publication time on the website front page. ### Understanding Anqi CMS Article Display Mechanism Anqi CMS uses template tags to call and display website data.

2025-11-08

How does AnQiCMS provide visitors with language switching options for content display?

In today's globally interconnected digital age, websites have become a basic need to provide content for users of different languages.No matter whether your business is aimed at the global market or simply wants to cover users in different dialect regions within the country, a website that supports multilingual switching can significantly improve user experience and brand influence.AnQiCMS (AnQiCMS) fully understands this need and provides an efficient and flexible solution to help your website seamlessly switch between multilingual content.

2025-11-08

How to customize the top navigation menu of a website and control its display?

The top navigation menu of the website is the first barrier for users to interact with content, and it directly affects users' understanding of the website structure and content.A well-designed, easy-to-operate navigation menu can significantly improve user experience and website professionalism.AnQiCMS (AnQiCMS) provides flexible and powerful features to help us easily customize and control the top navigation menu of the website to meet different design and operational needs.

2025-11-08

How to use the `replace` filter for string keyword replacement in AnQiCMS templates?

When operating content on AnQiCMS, we often encounter situations where we need to dynamically process the text output from the website template, such as uniformly modifying a brand name, correcting typographical errors, or adding prefixes/suffixes to specific keywords.At this time, the `replace` filter has become a powerful tool for us to meet these needs.It can help you flexibly adjust the string displayed on the page without modifying the original content data.### `replace` filter

2025-11-08

What is the core role of the `replace` filter in AnQiCMS website content display?

In AnQiCMS (AnQiCMS) website content display, the `replace` filter plays a core and practical role, giving content operators the ability to flexibly control the front-end display of content without modifying the original data.In simple terms, this filter helps us replace a specific string in the content with another, thus achieving various refined display adjustments.This function's core value lies in its 'non-intrusiveness' and 'high efficiency'.

2025-11-08