How to use the `archiveList` tag to display the latest 10 article titles and summaries on the homepage?

Calendar 👁️ 63

In Anqi CMS, the homepage often plays a crucial role in displaying the latest content and attracting visitors' attention. If you want to clearly list the titles and summaries of the latest 10 articles on the homepage,archiveListThe tag is a powerful tool to achieve your goal. It is flexible and easy to use, allowing you to easily present dynamic content in the most prominent position on the website.

We need to usearchiveListSeveral core parameters are used to filter and display data. This tag is usually used to obtain lists of various documents, whether articles, products, or other custom content models, it can be very useful.

First, you need to open the homepage template file of your website. Depending on the organization of your template, this may betemplate/your_template_name/index/index.htmlortemplate/your_template_name/index.html.

In the template file, we will construct it in this wayarchiveListTags:

{% archiveList archives with type="list" limit="10" order="id desc" moduleId="1" %}
    {% for item in archives %}
    <div class="latest-article-item">
        <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
        <p>{{item.Description|safe}}</p>
        <span class="article-date">发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        <a href="{{item.Link}}" class="read-more">阅读详情</a>
    </div>
    {% empty %}
    <p>暂时没有文章可供展示。</p>
    {% endfor %}
{% endarchiveList %}

Let's parse this code step by step, and see what each parameter and part does:

  • {% archiveList archives with ... %}This isarchiveListThe start of a tag,archivesThis is the variable name given to the list of articles obtained. Inside the tag, we pass various parameters through thewithkeywords.
  • type="list"This parameter specifies that we are getting a list of a fixed number, not a paginated list. Because we explicitly want to display 10 articles, solisttype is more suitable.
  • limit="10"This is the key to controlling the display of article numbers. It is set to10This means that only the latest 10 articles are obtained.
  • order="id desc"This parameter determines the sorting method of the articles.id descMeans to sort by article ID in descending order. In Anqi CMS, article IDs are usually self-increasing, so the larger the ID, the later the article was published, ensuring that the latest published articles are obtained.You can also chooseorder="CreatedTime desc"It will sort the articles in reverse order based on the creation time, with a similar effect.
  • moduleId="1": Anqi CMS supports various content models (such as articles, products, pages, etc.).moduleId="1"It is usually used to specify that we only want to get the content under the "article model".If your article model ID is not 1, please adjust it according to the actual situation. You can view or edit the model ID in the background "Content Management" -> "Content Model".
  • {% for item in archives %}This is a loop statement, it will traversearchiveListTagged data of each article obtained, and the data of the current article is assigned toitemVariable.
  • <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>: Inside the loop, we useitem.TitleTo get the title of the article and useitem.LinkGenerate a link to the article details page.
  • <p>{{item.Description|safe}}</p>:item.DescriptionIt is the introduction of the article. Here, an additional|safefilter is used. If the article introduction may contain HTML tags (such as bold, italic, etc.),|safeThe filter ensures that these HTML tags are parsed correctly rather than displayed as plain text.
  • <span class="article-date">发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>:item.CreatedTimeIs the creation time of the article (a timestamp). We usestampToDateThe function formats it into a readable date format, for example, “2006-01-02” will be displayed as “2023-10-27”.
  • {% empty %}IfarchiveListThe tag did not find any articles that meet the criteria (for example, the website has just been set up and no articles have been published),emptyThe content within the tags will be displayed, which is a friendly user prompt.
  • {% endfor %}and{% endarchiveList %}: They are loop andarchiveListthe end tag marker.

Place this code in the appropriate position of your homepage template, save it, and refresh your website homepage. You should then see the latest 10 article titles and summaries neatly arranged on the page.You can add CSS styles to these elements based on your website design to make them look more beautiful.


Frequently Asked Questions (FAQ)

How to only display the latest 10 articles in a specific category instead of the latest articles from the entire site?

If you want to only display the latest articles in a specific category, you canarchiveListadd acategoryIdParameters. For example, if you want to display the category ID of5article, you can modify the code to:

{% archiveList archives with type="list" limit="10" order="id desc" moduleId="1" categoryId="5" %}
    {# ... 循环内容不变 ... #}
{% endarchiveList %}

You can find the corresponding category ID in the "Content Management" -> "Document Category" of the Anqi CMS backend. If you need to display articles of multiple categories, the IDs can be separated by commas, for example,categoryId="5,8,12".

2. How can I modify it to display not the latest article but the top 10 articles with the highest views?

To display the article with the highest views, just modifyorderthe parameter.order="id desc"changed toorder="views desc",viewsRepresents the number of page views of the article.

{% archiveList archives with type="list" limit="10" order="views desc" moduleId="1" %}
    {# ... 循环内容不变 ... #}
{% endarchiveList %}

Thus,archiveListThe tags will be sorted from high to low according to the number of page views of the article, thus displaying the 10 most popular articles on the website.

3.type="list"andtype="page"What is the difference and when should it be usedtype="page"?

type="list"Used to get a fixed number of article lists, as we do in this example.It does not automatically generate pagination navigation, suitable for displaying a small number of articles in the sidebar, fixed area on the homepage, and other places.

type="page"It is used to retrieve a paginated list of articles. When you need to display a large number of articles on a single page and want to browse more content through 'previous page', 'next page', or page number jumps, you should usetype="page". Withpaginationtag, type="page"It will automatically handle pagination logic and generate pagination links. For example, on the article list page or search results page,type="page"is the better choice.

Related articles

How to customize the layout and content display of the article detail page in AnQi CMS?

AnQiCMS (AnQiCMS) is a highly flexible content management system that provides great freedom to content operators, especially in customizing the layout and content display of article detail pages.Understanding the underlying mechanism and operation methods can help us better create personalized pages that meet user needs and optimize SEO performance.Why do you need a custom article detail page?In website operation, the article detail page is not only a carrier of content, but also a key touchpoint for users to deeply interact with information and achieve conversion goals.The standardized template is convenient and fast

2025-11-08

How to convert the original image address to a thumbnail address for display?

In modern website operations, images play a crucial role, not only enhancing the attractiveness of the content but also effectively conveying information.However, very large image files can significantly slow down website loading speed, harm user experience, and even affect search engine rankings.Therefore, converting the original image address to an optimized thumbnail address for display is an important part of website performance optimization.AnQiCMS as an efficient content management system fully considers the needs of image processing, built-in powerful thumbnail generation and management functions.Configure and template calls reasonably

2025-11-08

How to debug variables in a template and display their structure and values?

During the development and maintenance of website templates, we often encounter such situations: a page element does not display as expected, or data seems missing or incorrectly formatted.This is the key to quickly locate the problem, as you can clearly view the structure and specific values of variables in the template.For users who use AnQiCMS, the system provides powerful and convenient debugging tools to help us easily "penetrate" template data.Why do we need to debug template variables? Data is passed through variables in the AnQiCMS template.

2025-11-08

How to remove extra spaces or characters from a string before displaying content?

During the operation of a website, we often encounter unnecessary spaces, line breaks, or special characters in the content. These 'impurities' not only affect the appearance of the content and the user's reading experience, but may also have a negative impact on the layout of the page and search engine optimization (SEO).AnQiCMS (AnQiCMS) is an efficient content management system that provides flexible and powerful template functions, among which the built-in template filters are the tools to solve such problems.Before you display content on the page, clean the string

2025-11-08

How to call and display product custom parameters (such as price, stock) on the product detail page?

In website operation, especially for product display websites, product details are far more than just titles and descriptions.In order to better meet user needs, it is particularly important to display various personalized parameters such as product price, inventory, color, material, and so on.AnQiCMS (AnQiCMS) takes advantage of its flexible content model and powerful template tag features, allowing you to easily call and display these custom parameters on product detail pages.### Preparations: Define Product Custom Parameters To display custom parameters on the product detail page, you first need to define these parameters in the AnQi CMS backend

2025-11-08

How to implement lazy loading of images in article content to improve page loading speed and user experience?

In today's fast-paced online world, website loading speed is crucial for user experience and search engine rankings.If your website content contains a large number of images, optimizing their loading method will be a key step in improving website performance.Image lazy loading (Lazy Load) is a highly efficient solution. Why Image Lazy Loading is So Important? While website images can enrich content and enhance visual appeal, they are also often the main reasons for slow page loading.When a page carries many high-resolution images

2025-11-08

How to configure and display multilingual content in AnQi CMS to serve users in different regions?

In today's global internet environment, enterprises and content operators often need to provide content to users from different countries and regions.AnQiCMS (AnQiCMS) understands this need and therefore provides flexible and powerful multilingual content configuration and display capabilities, helping users easily expand into international markets and directly reach audiences with different language preferences.### Overview of AnQi CMS Multilingual Capabilities AnQi CMS considers multilingual support as one of its core strengths, aiming to provide users with a complete global content publishing solution

2025-11-08

How to use the `categoryList` tag to build and display a multi-level, nested category navigation menu?

In website operation, a clear and easy-to-navigate menu structure is a core factor in improving user experience and search engine friendliness.For websites with a large amount of content or a variety of product lines, it is particularly important to build a multi-level, nested category navigation menu.AnQiCMS provides powerful template tag functions, where the `categoryList` tag is the key to achieving this goal.This article will delve into how to use the `categoryList` tag to flexibly build and display your multi-level category navigation menu

2025-11-08