How does AnQiCMS display the latest article list on the homepage?

Calendar 👁️ 65

The homepage is the first impression of a visitor arriving at the website, and a timely updated list of the latest articles can effectively enhance the vitality and user stickiness of the website.For users of AnQiCMS, displaying the latest published article list on the homepage is a basic and important feature, which can be easily realized through the flexible template tags provided by the system.

AnQiCMS, with its high efficiency and customizable features, provides users with an intuitive template system.You don't need to delve deeply into complex backend code, just master its powerful template tag usage, and you can freely organize and display content on the website frontend.

Step 1: Find your homepage template file

To modify the homepage content, you first need to locate the homepage template file currently in use on the website. Typically, the Anqi CMS template files are located in the root directory of your website./template/Inside the folder. Within it, you will find a folder named after your theme (for exampledefault), after entering the folder, the homepage template file is usually namedindex.htmlor located atindex/index.html.

If you are unsure which file it is, you can check the folder of your themeconfig.jsonfile, it will define the basic information of the theme. Once you find itindex.htmlFile, you can start editing it to add the display logic for the latest article.

Step two: UnderstandarchiveListThe core usage of tags

AnQiCMS providedarchiveListLabel, this is a core tool for retrieving article lists. In order to display the latest published articles on the homepage, we need to configure this label to retrieve content under a specific model (usually the 'article model') and sort it in descending order by publication time.

archiveListThe tag has several key parameters, which are crucial for displaying the latest article.

  • moduleIdSpecify which content model's articles to retrieve. In AnQiCMS, the 'article model' usually corresponds tomoduleIdWith1. If you have a custom article model, please set it according to the actual model ID in the background "Content Management" -> "Content Model".
  • order: Defines the sorting method of articles. To display the most recently published articles, we usually useid desc(Sorted by article ID in descending order, with newer article IDs being larger) orCreatedTime desc(Sorted by creation time in descending order). Both can achieve the effect of displaying the latest articles,id descusually more concise.
  • limit: Controls the number of articles to display. For example,limit="5"will display the latest 5 articles.
  • type: Usually set tolistIt indicates getting a simple list of articles, not a list with pagination features (the home page usually does not need pagination).

Combine these parameters, the basic structure of the latest article list call is as follows:

{% archiveList latestArticles with moduleId="1" order="id desc" limit="5" type="list" %}
    {% for article in latestArticles %}
        <!-- 在这里编写每篇文章的展示HTML结构 -->
    {% endfor %}
{% endarchiveList %}

In this code block,latestArticlesIs a custom variable name used to store the latest article data you can accessforthrough the looparticleVariables to access the details of each article.

Step 3: Build the display structure of the article.

In{% for article in latestArticles %}Within the loop, we can usearticleVariables to access various attributes of each article and present them on the web. Common article attributes include:

  • article.Title: Article title
  • article.Link: Article detail page link
  • article.Description: Article summary or introduction
  • article.CreatedTime: Article publish time (timestamp format)
  • article.Thumb: Article thumbnail address
  • article.CategoryId: Article category ID

Let's gradually improve the article display structure:

  1. Display article title and link:

    <h3><a href="{{ article.Link }}" title="{{ article.Title }}">{{ article.Title }}</a></h3>
    
  2. Format the display time:AnQiCMS providedstampToDateThe label can convert the timestamp into a readable date and time string. The date formatting method in the Go language is quite special, for example2006-01-02 15:04:05represent年-月-日 时:分:秒.

    <p class="article-meta">发布于:<span>{{ stampToDate(article.CreatedTime, "2006年01月02日") }}</span></p>
    
  3. Show article summary:

    <p class="article-description">{{ article.Description }}</p>
    

    Herearticle.DescriptionIf you do not manually fill in the summary when publishing an article in the background, the system will automatically extract a part of the article content as a summary.

  4. Show article thumbnail:If the article is set to have a thumbnail, it can be displayed to increase visual appeal.

    {% if article.Thumb %}
        <div class="article-thumbnail">
            <a href="{{ article.Link }}" title="{{ article.Title }}">
                <img src="{{ article.Thumb }}" alt="{{ article.Title }}">
            </a>
        </div>
    {% endif %}
    
  5. Display the category of the article:You can combinecategoryDetailLabel, based onarticle.CategoryIdRetrieve and display the category name and category link of the article.

    {% if article.CategoryId %}
        所属分类:<a href="{% categoryDetail with name='Link' id=article.CategoryId %}">{% categoryDetail with name='Title' id=article.CategoryId %}</a>
    {% endif %}
    

Complete example code

Combine all elements above, and you can get a relatively complete list display area of the latest articles. You can place it in the homepage template (index.html) at the position you want to display.

<section class="latest-articles-section">
    <h2>最新动态</h2>
    <ul class="articles-list">
        {% archiveList latestArticles with moduleId="1" order="id desc" limit="5" type="list" %}
            {% for article in latestArticles %}
                <li class="article-item">
                    <div class="item-inner">
                        {% if article.Thumb %}
                            <div class="article-thumbnail">
                                <a href="{{ article.Link }}" title="{{ article.Title }}">
                                    <img src="{{ article.Thumb }}" alt="{{ article.Title }}">
                                </a>
                            </div>
                        {% endif %}
                        <div class="article-content">
                            <h3><a href="{{ article.Link }}" title="{{ article.Title }}">{{ article.Title }}</a></h3>
                            <p class="article-meta">
                                <span>发布于:{{ stampToDate(article.CreatedTime, "2006年01月02日") }}</span>
                                {% if article.CategoryId %}
                                    <span>所属分类:<a href="{% categoryDetail with name='Link' id=article.CategoryId %}">{% categoryDetail with name='Title' id=article.CategoryId %}</a></span>
                                {% endif %}
                            </p>
                            <p class="article-description">{{ article.Description|truncatechars:100 }}</p> {# 截取前100个字符 #}
                            <a href="{{ article.Link }}" class="read-more-btn">阅读全文 &raquo;</a>
                        </div>
                    </div>
                </li>
            {% empty %}
                <li class="no-content-message">目前还没有发布的文章,敬请期待!</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</section>

Please note:in the above codeclassproperties such aslatest-articles-section,articles-listmerely are

Related articles

How to display the previous article and

In website content operation, the user experience of the document detail page is crucial.A well-designed page not only effectively displays content but also guides visitors to delve deeper into more related information.Among them, providing the "Previous" and "Next" navigation functions for users is a commonly used and efficient strategy to improve the internal link structure of the website, reduce the bounce rate, and optimize the user's browsing path.This not only helps users conveniently explore more content, but also conveys the relevance and depth of the website's content to search engines, which has a positive impact on SEO.

2025-11-07

How to implement a paginated document list display in `archiveList`?

When managing website content, we often encounter such situations: there are many articles, products, or news under a certain category. If all the content is piled on a single page, it not only causes the page to load slowly and affects user experience, but also makes it difficult for visitors to find what they need in a sea of information.At this point, introducing pagination becomes particularly important. Pagination can break a large amount of content into several small pages, allowing users to browse page by page, greatly enhancing the usability and access efficiency of the website.In AnQiCMS, implementing a document list display with pagination is very intuitive and flexible

2025-11-07

How to use the `archiveList` tag to display a document list according to specified conditions (such as latest, most popular, recommended attributes)?

AnQiCMS is an efficient and flexible content management system that provides a variety of content display methods, among which the presentation of the document list is a very core part of website operation.We hope to dynamically display the latest articles, the most popular content, or carefully recommended high-quality documents on the homepage, category pages, or thematic aggregation pages according to different operational objectives.All of this can be easily achieved through the powerful `archiveList` tag of AnQiCMS

2025-11-07

How to correctly render Markdown content as HTML and display mathematical formulas and flowcharts in the Anqi CMS template?

The content is the soul of the website, and how to present these contents efficiently and beautifully is a topic of concern for every operator.In AnQi CMS, using Markdown to write content not only greatly improves writing efficiency, but also easily achieves complex layout requirements, such as inserting mathematical formulas and drawing flowcharts. This is undoubtedly a powerful feature for technical blogs, educational websites, or corporate websites that need to display complex business processes.Next, we will explore how to correctly render Markdown content as HTML in the Anqi CMS template

2025-11-07

How to display a document list on the AnQiCMS website based on a specific category ID?

In AnQiCMS, displaying a document list based on a specific category ID is a very basic and commonly used feature, which allows us to flexibly organize and present website content.AnQiCMS's powerful template tag system makes this operation intuitive and efficient.No matter where you want to manually insert a category of documents on a page, or want the entire category page to automatically display the documents under it, the system provides the corresponding solutions.

2025-11-07

What ways does AnQiCMS support for sorting the article list display, such as by views or publication time?

The display order of the website content list is one of the key factors affecting user experience and content operation effects.An excellent CMS system should provide a flexible sorting mechanism, allowing operators to freely adjust the display of articles according to content characteristics and promotion strategies.AnQi CMS deeply understands this, providing users with various ways to sort article lists, helping you accurately control content exposure and traffic guidance.### Core Sorting Feature: The Powerful Application of `archiveList` Tag In AnQi CMS

2025-11-07

How to get and display the detailed content of the current article in AnQiCMS template?

Build a content-rich website, the article detail page is undoubtedly the core.It carries the most specific and valuable information on the website, and it is also one of the pages where users spend the longest time and interact most frequently.In AnQiCMS (AnQi CMS), with its flexible template engine and rich tag system, we can easily obtain and elegantly display the detailed content of the current article.

2025-11-07

How to implement the display of multi-level navigation menus in AnQiCMS and support secondary dropdown menus?

A clear and intuitive navigation system is the key to the success of any website, it can guide visitors to quickly find the information they need and greatly enhance the user experience.AnQiCMS as an efficient content management system, provides flexible and powerful functions to build and manage the navigation menu of the website, including perfect support for multi-level structures and secondary dropdown menus. ### Define your navigation structure in AnQiCMS backend The first step in building a multi-level navigation menu in AnQiCMS is to configure it in the backend management interface.You can go to the **"Back-end Settings"** area

2025-11-07