How can you list the latest articles or products under a specified category in AnQiCMS?

Calendar 👁️ 65

Manage website content in AnQiCMS, often needing to display relevant information according to different topics or sections.For example, you may want to display the latest articles under the "Company News" category in some area of the homepage, or show the latest products under the "Hot New Products" category in the sidebar of the product page.AnQiCMS provides flexible and powerful template tags that allow you to easily achieve these content call requirements.

Understanding the content organization method of AnQiCMS is the key to efficiently utilizing its functions.The system distinguishes different types of content through 'content model', such as article model and product model.Under each content model, multiple "categories" can be created to further refine the content attribution.When you publish articles or products in the AnQiCMS backend, you need to assign them to specific content models and categories.This structured content management lays a solid foundation for our subsequent precise content calls through template tags.

We need to use one of the core template tags of AnQiCMS to list the latest articles or products in the specified category:archiveListThis tag is like an intelligent filter that can help us extract data that meets specific conditions from a massive amount of content.

archiveListCore parameter interpretation of the tag

In order to accurately call the latest content under the specified category, we need to masterarchiveListSeveral key parameters of the tag:

  1. moduleId: Specify the type of contentThis parameter is used to inform the system whether you want to call an article or a product.AnQiCMS defaults to having an article model (usually ID 1) and a product model (usually ID 2).You can view the specific ID of each model in the "Content Management" -> "Content Model" in the background.For example, if you want to list articles, you can setmoduleId="1"; If you want to display products, set it tomoduleId="2".

  2. categoryId: Precise classification positioningThis is the core parameter for implementing the 'specified category' call requirement.You need to provide the unique ID of the target category. This ID can be found in the AnQiCMS backend under "Content Management" -> "Document Category".When editing a category, you usually see the ID of that category in the URL or at some location in the editing interface.For example, if the ID of the "Company News" category is 10, then you can set the parameter tocategoryId="10".

  3. order: Sort rules to ensure "latest"To ensure that the content is "latest", you need to specify an appropriate sorting method. The two most common options are:

    • order="id desc": Arrange the content by ID in descending order, usually the larger the ID, the newer the content.
    • order="createdTime desc": Arrange according to the creation time in descending order, which can most accurately reflect the content's 'newness'. You can choose one according to your actual needs.
  4. limitControl the number of displayed items.This parameter is used to limit the number of items displayed at one time. For example, if you want to display only 5 of the latest articles, you can setlimit="5".

  5. type: List display form typeThe parameter has two main values:

    • type="list"Used for simple content list display, no pagination involved.
    • type="page"Used when you want the content list to support pagination, needs to be used withpaginationTags are used together.

Practice: Retrieve the latest articles or products under a specified category

Suppose we want to display the 5 latest articles under the 'Company News' category in a certain area of the website.

Step 1: Confirm the Category ID and Model ID

  1. Log in to the AnQiCMS backend, go to “Content Management” -> “Content Model”, confirm the ID of the “Article Model” (assuming it is1)
  2. Enter "Content Management" -> "Document Category", find the "Company News" category, and note its ID (assuming it is10)

Step 2: Write the template code

In your AnQiCMS template file (for example, the home page'sindex/index.htmlor the sidebar'spartial/sidebar.htmlYou can write code like this in Chinese:

<div class="latest-news-section">
    <h2>公司新闻</h2>
    <ul>
        {# 使用 archiveList 标签调用指定分类下的最新文章 #}
        {# moduleId="1" 表示调用文章模型的内容 #}
        {# categoryId="10" 表示只调用ID为10的“公司新闻”分类下的内容 #}
        {# order="createdTime desc" 确保内容按发布时间降序排列,即最新内容在前 #}
        {# limit="5" 限制只显示最新的5篇文章 #}
        {% archiveList latestPosts with moduleId="1" categoryId="10" order="createdTime desc" limit="5" %}
            {% for item in latestPosts %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {# 如果文章有缩略图,可以显示出来 #}
                        {% if item.Thumb %}
                            <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="news-thumb">
                        {% endif %}
                        <span class="news-title">{{ item.Title }}</span>
                        {# 格式化文章发布时间 #}
                        <span class="news-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                    </a>
                </li>
            {% empty %}
                {# 当该分类下没有内容时,显示此提示 #}
                <li><p>该分类下暂无最新文章。</p></li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

This code will traversearchiveListReturn the latest list of articles. For each article (itemWe can go through the}item.LinkGet its link,item.TitleGet the title,item.ThumbRetrieve thumbnails,item.CreatedTimeGet publish time

Related articles

How to use Django template engine syntax in AnQiCMS template to control the content display logic?

AnQiCMS is an efficient content management system developed based on the Go language, its template system uses a syntax similar to Django's template engine, which is undoubtedly an advantage for those familiar with web development to quickly get started and implement powerful content display logic.It allows us to flexibly control the presentation of content at the template level without writing complex backend code.To understand how to use this GoLang implemented Django template engine syntax in AnQiCMS templates to control content display logic

2025-11-08

Do I want to use a unique display template for specific articles or categories, does AnQiCMS support this?

In website operation, we often encounter such needs: some articles or categories, due to the particularity of their content or marketing needs, we hope to give them a completely different display style from the rest of the website.This personalized display requirement is particularly important in today's increasingly rich content.So, does AnQiCMS support using a unique display template for specific articles or categories?The answer is affirmative, and it provides powerful and flexible features to support you in achieving this goal.Why do you need a dedicated template?\n\nImagine

2025-11-08

How to understand the template file structure of AnQiCMS and effectively manage the display layout of the website?

Manage the display layout of the website in Anqi CMS, the core lies in understanding its flexible template file structure and powerful tag system.This can not only give your website a unique visual style, but also greatly improve the efficiency of content operation and user experience. ### One, Anqi CMS template overview: the foundation for building a website Imagine that your website is a house, and the Anqi CMS template system is the design图纸 and construction tools for this house.It is based on the efficient backend of Go language, but it adopts syntax similar to the Django template engine in front-end templates

2025-11-08

What template types does AnQiCMS support to adapt to content display on different devices?

Whether website content can be seamlessly and beautifully displayed on various devices in today's multi-screen era is directly related to user experience and brand image.AnQiCMS as an enterprise-level system focusing on efficient content management, fully understands the importance of this demand, and therefore provides a flexible and diverse range of solutions in template support to ensure that your website content can be presented in a **state** on desktop computers, tablets, or mobile phones.To meet the needs from simple and efficient to highly customized, AnQiCMS meticulously designed three core website modes to handle the display of different devices

2025-11-08

What sorting and filtering options does AnQiCMS provide to control the display order of list content?

How to efficiently display and organize content in website operation directly affects the user experience and the efficiency of information transmission.For users who use AnQiCMS, the system provides various flexible sorting and filtering options to help us accurately control the display order of list content. Whether it is articles, products, or other custom content types, they can be presented to visitors in the most business-friendly way possible.The AnQi CMS has given the control of content display order to the user, which is mainly realized through a powerful template tag system and backend management settings.Through these features

2025-11-08

How to display a list of related articles based on the keywords or custom associations of an article?

In website content operation, providing users with a list of relevant articles can not only effectively extend the visitor's stay time on the website and reduce the bounce rate, but also through guiding users to discover more interesting content, optimize the internal traffic path, and have a positive impact on SEO performance.AnQiCMS (AnQiCMS) understands this need and provides flexible and powerful functions, allowing us to easily display lists of related articles based on keywords or custom associations.###

2025-11-08

How to call and display the custom fields of an article on the article detail page?

In Anqi CMS, the content display of the article detail page is highly flexible, especially for fields customized through the content model.These custom fields can help us manage and display different types of information more precisely, such as product prices, authors' origins, and property layouts, etc.How can you accurately call and display the content of these custom fields on the article detail page?This article will introduce this process in detail. ### 1. Custom field creation and filling: laying the content foundation In AnQi CMS

2025-11-08

How to display the 'Previous' and 'Next' article links and titles on the article detail page?

It is crucial to enhance user experience and content discoverability in website operation.When a reader is immersed in an article, providing navigation links to the "previous article" and "next article" can not only guide them to continue browsing the website's content but also effectively reduce the bounce rate and optimize the on-site SEO structure.For those of us using the AnQiCMS website to manage, implementing this feature is both simple and efficient.AnQiCMS provides a straightforward and powerful template tag system, making it easy to integrate 'Previous Article' and 'Next Article' links on article detail pages

2025-11-08