How to display a list of articles or products under a specific category in AnQiCMS?

Calendar 👁️ 69

In AnQiCMS, displaying a list of articles or products under a specific category is a common requirement in website content management.To build subpages under the navigation menu or to display selected content of different modules on the homepage, AnQiCMS provides a flexible and powerful way to achieve this goal.Understanding the content organization logic and the use of template tags will allow you to easily present the required content on the website.

Understanding the content model and categories of AnQiCMS

Firstly, the organization of AnQiCMS content is based on 'content model' and 'category'.Content modelIt is like the 'skeleton' or 'type' of content, for example, the 'article model' is used to publish news, blogs, while the 'product model' is used to display products.Different models can have custom fields to meet the storage needs of different types of content.In the AnQiCMS backend, you can find the management entry for these models and set unique properties for them.CategoryIt is the specific organizational structure under the content model, which is usually hierarchical and can have multiple levels.For example, under the "Article Model", you can create categories such as "Company News", "Industry Dynamics", and so on;Under the "product model", there can be categories such as "electronic products", "home goods", and so on.Each category belongs to a specific content model.

When you need to display specific content on a website, you usually specify the ownership of the contentModel ID(moduleId)andCategory ID (categoryId)to get it accurately. Typically, the corresponding article model ismoduleIdIt could be 1, the product model could be 2, and the specific ID can be viewed on the content model management page in the background.The category ID is generated by the system when creating or editing a category, and you can also find it on the category management page.

Practice operation: Call the list under a specific category in the template

In AnQiCMS template files,archiveListTags are the core tools used to retrieve lists of articles or products. This tag is very flexible and can filter, sort, and display content according to your needs.

To display articles or products under a specific category, you can do this:

{% archiveList archives with moduleId="1" categoryId="5" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <img src="{{item.Thumb}}" alt="{{item.Title}}">
            <h3>{{item.Title}}</h3>
            <p>{{item.Description}}</p>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </a>
    </li>
    {% empty %}
    <li>当前分类下暂无内容。</li>
    {% endfor %}
{% endarchiveList %}

In this code block:

  • {% archiveList archives with ... %}It is the start of the list call,archivesIt is a variable name set for the content list obtained.
  • moduleId="1"Specify the content we need to retrieve from the article model (assuming the article model ID is 1). If you need to display products, you can change it to the corresponding product model ID, such asmoduleId="2".
  • categoryId="5"Then it precisely specifies the content we want to obtain under the category with ID 5.You can replace it with the category ID you wish to display. Usually, if you want to include all the subcategory content under the category,childThe parameter is set to default.trueIt does not require additional settings.
  • limit="10"Limited the number of displayed articles or products to 10. You can adjust this number according to the page layout.
  • {% for item in archives %}Loop through each item obtained in the iteration. In the loop,itemrepresenting the article or product currently being processed.
  • {{item.Link}}/{{item.Title}}/{{item.Thumb}}/{{item.Description}}Common fields of content items, representing their links, titles, thumbnails, and summaries, etc.{{stampToDate(item.CreatedTime, "2006-01-02")}}Used to format the publishing time of the content.
  • {% empty %}The part will display a custom prompt when there is no content.

This code can be placed in any template file on your website, such as the homepage, sidebar, or a dedicated list page, as long as it needs to display content for a specific category.

Advanced Technique: Combine Pagination with Dynamic Category Display

Implement pagination display:If there are many items under a category, you may need to paginate the display. Just set thearchiveListlabel'stypethe parameter to"page"and combiningpaginationLabel it:

{% archiveList articles with moduleId="1" categoryId="5" type="page" limit="10" %}
    {# 文章列表内容与上述相同 #}
    {% for item in articles %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% endfor %}
    {% empty %}
    <li>当前分类下暂无内容。</li>
{% endarchiveList %}

<div class="pagination">
    {% pagination pages with show="5" %}
        <a href="{{pages.FirstPage.Link}}">首页</a>
        {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">上一页</a>{% endif %}
        {% for page in pages.Pages %}<a class="{% if page.IsCurrent %}active{% endif %}" href="{{page.Link}}">{{page.Name}}</a>{% endfor %}
        {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">下一页</a>{% endif %}
        <a href="{{pages.LastPage.Link}}">尾页</a>
    {% endpagination %}
</div>

Here, limit="10"It is no longer the total number of displays, but the number of items displayed per page.paginationTags will generate navigation links based on the current page number and total number of pages.

Dynamically obtain the current category ID: If you are on a category page (for examplearticles/list-news.html), and you want to display articles under the current category without hardcodingcategoryId,AnQiCMS will automatically identify the category information of the current page. You can even get more detailed information about the current category throughcategoryDetailtags, such as category title, description, etc.

”`twig {# In the category list page template #} {% categoryDetail currentCategory with name=“Id” %} {# Get the current category ID #}

{% if currentCategory %} {# Make sure to get the category ID #}

{% archiveList articles with moduleId="1" categoryId=currentCategory type="page" limit="10" %}
    {% for item in articles %}
        <li><a href="{{item.Link}}">{{item.Title}}</a></li>
    {% endfor %}
    {% empty %}

Related articles

How to retrieve and display a list of articles or products in a loop?

Build an energetic website in AnQiCMS, the display of the content list is an indispensable part.Whether it is to display the latest released articles, hot products, or content under specific categories, AnQiCMS' powerful template engine can help us easily achieve it.This article will delve into how to retrieve and loop through lists of articles or products in AnQiCMS, helping you flexibly build diverse content display pages.## Understanding AnQiCMS content list mechanism AnQiCMS uses a template engine syntax similar to Django

2025-11-07

How to dynamically generate and display the top or bottom navigation menu of a website?

In website operation, the top and bottom navigation menus play a vital role. They are not only guides for users to explore the website's content but also crucial for search engines to understand the website's structure.A well-designed, dynamically generated navigation menu that can greatly enhance user experience and website maintainability.AnQiCMS provides a set of intuitive and powerful features to help you easily achieve this goal.### Backend Configuration: Bring Your Menu to Life To dynamically generate and display navigation menus in AnQi CMS, you first need to configure the menu content in the backend

2025-11-07

How to generate and display multi-level breadcrumb navigation in AnQi CMS?

In website content operation, a clear navigation path is crucial for user experience and search engine optimization.A good breadcrumb navigation can help users quickly understand the current page's position in the website structure and make it convenient for them to backtrack to the previous level or higher-level pages.AnQiCMS (AnQiCMS) fully understands this, therefore it provides a powerful and easy-to-use breadcrumb navigation feature that allows website administrators to easily generate and display multi-level breadcrumbs.The core of implementing breadcrumb navigation in Anqi CMS lies in its built-in `breadcrumb` tag

2025-11-07

How to configure and display SEO title, keywords, and description (TDK) on the website homepage?

In website operation, the search engine optimization (SEO) of the homepage is crucial.A well-configured SEO title, keywords, and description (TDK) can significantly improve the visibility of a website in search engine results pages (SERP), attracting more potential visitors.AnQiCMS (AnQiCMS) is a system designed for SEO-friendliness, providing an intuitive and convenient way to manage key information.This article will guide you to understand how to configure and display SEO title, keywords, and description on the homepage of your AnQiCMS website.--- ### One

2025-11-07

How to display document recommendation attributes (such as headline, recommendation) on the document list or detail page?

It is crucial to highlight the key content on the website in a content management system to attract users and increase page views.AnQiCMS (AnQiCMS) provides powerful document recommendation attribute functions, allowing website operators to flexibly mark and display articles.This article will introduce how to cleverly use these recommended attributes in the document list and detail page of Anqi CMS to make your website content more vivid and guiding.### Learn about the recommended features of AnQi CMS AnQi CMS has designed various recommended features for each document

2025-11-07

How to display the detailed content of articles or products and support lazy loading of images?

A Guide to Displaying Content Details and Lazy Loading Images in AnQi CMS in Today's Digital World, the way websites present content directly affects user experience and search engine rankings.Whether it is a detailed article introduction or a beautiful product display, how to present the content efficiently and aesthetically to the visitors and ensure the website loading speed is a challenge that every operator needs to face.AnQiCMS (AnQiCMS) is a powerful content management system that provides us with flexible tools to meet these challenges.This article will delve into how to fully utilize the functions of Anqi CMS

2025-11-07

How to get and display the previous/next content of the current document?

In content-based websites, providing visitors with a convenient navigation experience is crucial, among which the 'Previous' and 'Next' functions are standard features of the article detail page.They can not only guide users to continue browsing more content, effectively increase the website's PV (Page View), but also help search engines better understand the structure of the website's content to optimize SEO performance.AnQiCMS fully considered this requirement, providing us with very simple and intuitive template tags to easily implement this feature.### Learn about AnQiCMS template mechanism At

2025-11-07

How to display the list of recommended content related to the current document in AnQi CMS?

When operating a website, we often hope that users can smoothly find more interesting content after reading a wonderful article.This not only extends the user's stay time and reduces the bounce rate, but is also an effective way to enhance the overall value of the website's content and SEO performance.AnQi CMS knows this, and therefore it provides a variety of flexible ways to display the recommended content list related to the current document, helping us better guide users. To implement recommendations for related content, we first need to understand how Anqicms defines 'related'.In system design, "related" can be reflected at several levels

2025-11-07