How to call and display the subcategory list or associated article list under a specified category in AnQiCMS?

Calendar 78

When using AnQiCMS for website content management, we often need to display information based on a specific content organization method.How to flexibly call and display the list of subcategories under a specified category, or the list of articles associated with the category, is a scenario that many users will encounter.AnQiCMS powerful template engine and rich tag functions, making it intuitive and efficient to meet these requirements.

AnQiCMS uses a syntax similar to the Django template engine, which means you can retrieve and render data through concise tags without delving into complex programming code.This allows content operation personnel to easily handle the display logic of website content even without a deep development background.

Flexible calling and displaying the subcategory list under a specified category

When building the navigation, sidebar, or content index of a special page, we often need to list all the subcategories under a main category. AnQiCMS providescategoryListLabels can help us easily achieve this goal.

The most critical parameter is to call the subcategory list under the specified category.moduleIdandparentId.moduleIdUsed to specify the type of content model you want to retrieve (such as article model, product model, etc.), usually the ID corresponding to the article model is1, the product model could be2You can view the specific content in the background content model management.parentIdIt refers to specifying which category's subcategory you want to retrieve. IfparentIdis set to0You will get all top-level categories. If you want to get the subcategories under a specific category (such as ID forXcategory) under, just setparentIdis set toXJust do it.

Here is an example of how to call a specific category under an article model (for example, let's assume the category ID is10) example of the subcategory list:

{% categoryList subCategories with moduleId="1" parentId="10" %}
    <ul class="sub-category-list">
        {% for category in subCategories %}
            <li>
                <a href="{{ category.Link }}" title="{{ category.Title }}">{{ category.Title }}</a>
                {% if category.HasChildren %}
                    {# 如果子分类还有下级,可以继续嵌套调用,或者仅显示一层 #}
                    <span class="has-children-indicator">»</span>
                {% endif %}
            </li>
        {% empty %}
            <p>该分类下暂无子分类。</p>
        {% endfor %}
    </ul>
{% endcategoryList %}

In this code block,subCategoriesIt is the variable name defined for the subcategory list obtained.category.Linkandcategory.TitleIt will output the link and name of each subcategory separately.category.HasChildrenIt is a boolean value that can be used to determine whether the current category has deeper-level subcategories for different display processing on the front end.

Retrieve and display the list of associated articles under a specified category

In addition to displaying subcategories, we are more likely to display the content of articles under a specific category. AnQiCMS'sarchiveListTags are a powerful tool for handling such needs. They can not only retrieve article lists but also perform various filtering and sorting operations.

To display articles under a specified category, it is also necessary to be clear.moduleIdandcategoryId.categoryIdSet the category ID of the article you want to display. In addition,limitThe parameter can control the number of articles displayed,orderThe parameter can define the sorting rule (such as in reverse order by publication timeid descor sorted by view countviews desc)typeThe parameter determines the type of the list,listmeans to get a fixed number of lists,pagemeans you want to display in paginated mode.

The following is an example of displaying a category ID of15The example of the article list under the article model, including simple pagination:

<div class="category-articles">
    {# 调用分类ID为15的文章列表,每页显示10篇文章,并启用分页 #}
    {% archiveList articles with categoryId="15" moduleId="1" limit="10" order="id desc" type="page" %}
        {% for article in articles %}
            <div class="article-item">
                <a href="{{ article.Link }}" title="{{ article.Title }}">
                    <h3>{{ article.Title }}</h3>
                    {% if article.Thumb %}
                        <img src="{{ article.Thumb }}" alt="{{ article.Title }}" class="article-thumb">
                    {% endif %}
                    <p>{{ article.Description|truncatechars:100 }}</p> {# 截取前100个字符作为简介 #}
                    <span class="publish-date">发布于:{{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                    <span class="views">阅读量:{{ article.Views }}</span>
                </a>
            </div>
        {% empty %}
            <p>该分类下暂无文章。</p>
        {% endfor %}

        {# 结合分页标签,生成分页链接 #}
        {% pagination pages with show="5" %}
            <div class="pagination-controls">
                {% if pages.FirstPage %}
                    <a href="{{ pages.FirstPage.Link }}">首页</a>
                {% endif %}
                {% if pages.PrevPage %}
                    <a href="{{ pages.PrevPage.Link }}">上一页</a>
                {% endif %}
                {% for pageItem in pages.Pages %}
                    <a href="{{ pageItem.Link }}" class="{% if pageItem.IsCurrent %}active{% endif %}">{{ pageItem.Name }}</a>
                {% endfor %}
                {% if pages.NextPage %}
                    <a href="{{ pages.NextPage.Link }}">下一页</a>
                {% endif %}
                {% if pages.LastPage %}
                    <a href="{{ pages.LastPage.Link }}">末页</a>
                {% endif %}
            </div>
        {% endpagination %}
    {% endarchiveList %}
</div>

In this example,articlesIt is the article list variable we define. We display the article title, thumbnail, introduction, publication date, and reading volume.truncatechars:100Is a filter used to truncate the introduction content to a specified length and add an ellipsis, which is very practical when displayed on the list page.stampToDateIs a label for formatting timestamps, which can beCreatedTimeThis timestamp is converted to a readable date format. Whentype="page"then,paginationTags are automatically generated for pagination links based on the context of the current list.

Combined use: Build a more dynamic display.

AnQiCMS template tags can be flexibly combined to build more dynamic page content.For example, you may want to list multiple top-level categories first on a page, and then display the latest few articles under each category.

`twig

{% categoryList mainCategories with moduleId="1" parentId="0" %} {# 获取文章模型下的所有顶级分类 #}
    {% for mainCategory in mainCategories %}
        <div class="main-category-block">
            <h2><a href="{{ mainCategory.Link }}">{{ mainCategory.Title }}</a></h2>
            <ul class="articles-in-category">
                {# 在每个顶级分类下,调用其最新的5篇文章 #}
                {% archiveList articlesInCategory with type="list" categoryId=mainCategory.Id limit="5" order="id desc" %}
                    {% for article in articlesInCategory

Related articles

How to display the 'Previous' and 'Next' document links and titles of the current article in AnQiCMS template?

The effective organization and convenient navigation of website content is the key to improving user experience and extending visit duration.When a visitor is immersed in your article, if they can seamlessly jump to related or adjacent content, it will undoubtedly greatly enhance the continuity of their browsing.AnQiCMS as a fully functional content management system provides intuitive and powerful template tags, helping us easily implement the display of 'Previous' and 'Next' document links and titles on article detail pages.

2025-11-09

How does AnQiCMS control the display or hide of paid content based on user group permissions?

In today's content is king era, how to effectively manage and monetize high-quality content is a focus for many website operators.It is particularly important to accurately control the content access permissions of different users for websites that provide membership services, paid courses, or exclusive information.

2025-11-09

How to use AnQiCMS's `archiveFilters` tag to dynamically display multi-dimensional content filtering conditions?

How to help visitors quickly find the information they are interested in on a content-rich website is the key to improving user experience and website efficiency.The traditional fixed category navigation often fails to meet users' multi-dimensional and personalized filtering needs.At this time, the `archiveFilters` tag provided by AnQiCMS can fully display its capabilities, helping us dynamically display multi-dimensional content filtering conditions, making your website content management and presentation more flexible and intelligent.

2025-11-09

How to automatically render Markdown format content to HTML when AnQiCMS displays article content?

In Anqi CMS, automatically rendering Markdown content into HTML is a core feature provided by the system, aiming to help content creators publish rich text content in a concise and efficient manner.This process is not a mysterious black box operation, but is achieved through clear settings and flexible template tags.

2025-11-09

How to integrate and display the custom contact information on the AnQiCMS frontend page, such as WhatsApp links?

On AnQiCMS, we often need to allow visitors to contact us in the most convenient way, and WhatsApp, due to its widespread usage, has become the preferred contact tool for many businesses and individuals.Luckyly, AnQiCMS was designed with flexibility in content and functionality in mind, allowing you to easily customize the contact information in the backend and display it on the front page of the website.This article will thoroughly introduce you to how to add and manage custom contact methods like WhatsApp in the AnQiCMS background

2025-11-09

Does the AnQiCMS 'Full Site Content Replacement' feature affect the display of frontend content immediately?

In content operations, sometimes we need to make unified adjustments to a large amount of content on the website, whether it is updating expired information, correcting brand names, or optimizing internal links, manual individual modification is undoubtedly a huge workload.AnQiCMS provides a powerful feature named 'Full Site Content Replacement', aimed at helping us efficiently solve such problems.However, many users may have a question when using this feature: Will the content on the website's front-end be immediately synchronized and updated after the full-site content replacement operation, so that visitors can see the latest modifications?

2025-11-09

How to use the AnQiCMS `tagList` tag to display a list of related tags and their links with the article?

In AnQiCMS, managing and displaying content, the Tag feature is very practical.It can not only help you better organize the content of the article, but also provide users with more flexible navigation methods, and is very beneficial for search engine optimization (SEO).When a reader is browsing an article, if they can see a list of related tags and can click on these tags to discover more similar content, it will undoubtedly greatly enhance the user experience and the website's PV (Page Views).

2025-11-09

How does AnQiCMS ensure that uploaded JPG/PNG images are automatically converted to WebP format to optimize front-end loading and display?

In today's digital age, website loading speed is crucial for user experience and search engine rankings.Among them, image files are an important part of web content, and their loading efficiency often directly affects overall performance.Traditional JPG and PNG image formats are widely used, but they are usually less efficient in file size than the emerging WebP format.How can AnQiCMS (AnQiCMS) automatically implement this optimization during image upload to enhance the front-end loading display of the website?

2025-11-09