How to display the latest published article list on the homepage of AnQiCMS?

Calendar 👁️ 59

In AnQi CMS, the homepage carries the important responsibility of attracting visitors and displaying the latest dynamics.Generally, displaying the latest article list in a prominent position on the homepage is an effective way to enhance user experience and guide content browsing.AnQi CMS with its flexible template system and powerful content management features makes this operation very direct and efficient.

Understand the content structure of Anqi CMS

Before getting started with showcasing the latest articles, we first need to have a basic understanding of the content organization method of Anqi CMS.AnQi CMS allows users to define different types of content through the 'content model', such as 'article model', 'product model', and so on.Every article belongs to a specific model and can be further divided into different categories.At the template level, Anqi CMS provides a rich set of tags to help us extract and display the required data from these structured contents.

The core method to display the latest article list on the homepage

We will mainly rely on the Anqicms provided to display the latest articles released on the homepagearchiveListTemplate tag. This tag is specifically used to retrieve lists of various documents (including articles) and provides multiple parameters to accurately control the content we want to display.

First, make sure your homepage template file (usually/template/你的模板名/index.html) is ready. Then, add it at the location where you want to display the article list,archiveList.

Key parameter analysis:

  • moduleIdThis parameter is used to specify which content model article you want to retrieve. By default, the article model usually corresponds tomoduleIdWith1. If you have customized the content model, please check the corresponding ID of your article model in the background "Content Management -> Content Model".
  • orderTo get the 'latest published' articles, we need to sort by publication time in reverse order. You can setorder="id desc"ororder="CreatedTime desc".id descusually means sorting in reverse order by the creation order of the articles in the database.CreatedTime descIt is clear that it is in reverse order according to the release time. In practice, the two may have similar effects, butCreatedTime descexpresses "latest release" more accurately.
  • limitThis parameter is used to control the number of articles displayed. For example,limit="10"It will display the most recent 10 articles.
  • type: By default,archiveListlabel'stypethe parameter to"list"It will directly list the specified number of articles.

How to build an article list:

archiveListThe tag creates an iterable array of articles within itself. We can useforLoop to process each article one by one, and extract the title, link, publication time, abstract, or thumbnail information of each article for display. Each article is usually named in the loop.itemYou can go throughitem.Title/item.Linkand so on.

For the publication time of the article, AnQi CMS returns a timestamp. In order to display it in the date format we are accustomed to, we need to usestampToDateLabel formatting. This tag is very flexible and can output various date and time styles based on the format string you provide.

Example code and interpretation

Here is a simple code example showing how to display the latest 5 articles published on the Anqi CMS homepage:

<section class="latest-articles">
    <h2>最新发布</h2>
    <ul class="article-list">
        {% archiveList archives with moduleId="1" order="CreatedTime desc" limit="5" %}
            {% for item in archives %}
                <li class="article-item">
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {% if item.Thumb %}
                            <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">
                        {% endif %}
                        <h3>{{ item.Title }}</h3>
                        <p class="article-meta">发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>
                        <p class="article-description">{{ item.Description|truncatechars:100 }}</p>
                    </a>
                </li>
            {% empty %}
                <li class="no-articles">目前还没有最新文章发布。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</section>

Code interpretation:

  1. {% archiveList archives with moduleId="1" order="CreatedTime desc" limit="5" %}:
    • Here is a variable namedarchivesthat will contain the list of articles we have retrieved.
    • moduleId="1"We specified that we are getting the content under the 'article model'.
    • order="CreatedTime desc"Ensure that the articles are arranged from new to old based on the publication time.
    • limit="5"Limited to displaying only the latest 5 articles.
  2. {% for item in archives %}: Loop through.archivesEach article. In each loop, the data of the current article can be accessed throughitemVariable access.
  3. {% if item.Thumb %}<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="article-thumb">{% endif %}: This part of the code checks if the article has a thumbnail (item.Thumb), and if it does, it displays the picture.
  4. <h3>{{ item.Title }}</h3>: Display the article title.
  5. <p class="article-meta">发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>:
    • item.CreatedTimeGet the timestamp of the article's publication.
    • stampToDate(..., "2006-01-02")Format the timestamp into a string in the format of “Year-Month-Day”. You can modify the format string as needed, for example"2006年01月02日 15:04"Will display more detailed time.
  6. <p class="article-description">{{ item.Description|truncatechars:100 }}</p>: Display the summary of the article (item.Description) Here, the following was used.truncatechars:100Filter, truncates the summary to a maximum of 100 characters, and automatically adds an ellipsis to prevent the content from being too long and affecting the layout.
  7. {% empty %}<li class="no-articles">目前还没有最新文章发布。</li>{% endfor %}: This is a very practical structure. IfarchivesThe list is empty (i.e., no articles meet the criteria), it will displayemptythe content of the block instead of displaying an empty list.

**Practical Recommendations and Optimization**

  • Control the number of displays.The home page article list should not be too long, generally 5-10 articles are enough, too many articles may affect page loading speed and user attention.
  • Optimize image loadingIf you have many thumbnails in your article, consider adding the lazy load attribute to the images to improve the loading speed of the first screen.The AnQi CMS supports lazy loading of images in content details.
  • Improve article contentEnsure each article has a clear title, an attractive thumbnail, and a concise summary. These elements are crucial for increasing the click-through rate of the article list.
  • SEO-friendly: Article titles and links are an important part of search engine optimization, ensuringitem.Titleanditem.Linkproper use helps search engines better understand your content.

By following these steps, you can easily display the latest published article list on the homepage of the Anqi CMS website.The AnQi CMS template tag function is powerful and intuitive, making content display very flexible.


Frequently Asked Questions (FAQ)

1. Can I display the latest articles in a specific category on the homepage?

Of course you can. You canarchiveListthe tag withcategoryIdParameters to specify the ID of one or more categories. For example, to display the latest articles with category ID 2, you can change the tag to:{% archiveList archives with moduleId="1" categoryId="2" order="CreatedTime desc" limit="5" %}If you want to display multiple category articles, the IDs should be separated by commas, likecategoryId="2,3,4".

What will be displayed if my article does not have an uploaded thumbnail?

In Anqi CMS, if you do not manually upload a thumbnail when publishing an article, but the article content contains images, the system will automatically try to extract the first image in the article content as a thumbnail. If the article content does not contain any images either, then in the templateitem.Thumboritem.LogoWill be empty, you can use{% if item.Thumb %}such a judgment to avoid displaying a broken image link, or set a default placeholder to ensure the beauty of the page.

3. How to adjust the display format of the article publishing time?

The display format of the article publishing time is determined bystampToDateThe second parameter (format string) determines. This format string follows the Go language's time formatting rules. For example:

  • "2006-01-02": Display as年-月-日For example,2023-10-27)
  • "2006年01月02日": Display asXXXX年XX月XX日For example,2023年10月27日)
  • "2006-01-02 15:04": Display as年-月-日 时:分For example,2023-10-27 14:30) You can modify this format string according to your needs to achieve the desired display effect.

Related articles

How to remove specific characters or spaces from the beginning and end of a string in AnQiCMS template?

When using AnQiCMS for website content management, we often encounter situations where we need to refine the output strings in the template.For example, the text obtained from the database may contain unnecessary leading and trailing spaces, or in some specific scenarios, it may be necessary to remove the specific symbols from the beginning or end of the string to ensure the neat display of the page and the uniformity of data format.The powerful template engine of AnQi CMS provides a variety of practical filters that can easily handle these string processing requirements.

2025-11-08

How to define the `stringformat` filter using Go's `fmt.Sprintf` format?

In AnQi CMS template design, the flexibility of data display is a key aspect that template developers highly value.The system is built-in with multiple filters (Filters) to process and format variables.Among them, the `stringformat` filter is a versatile tool that allows us to control the output format of any type of data with the powerful format definitions of the Go language `fmt.Sprintf` function, whether it is numbers, strings, or more complex data structures, all can be displayed in the expected style.What is

2025-11-08

How to use the `stringformat` filter to format a floating-point number as a string with two decimal places?

In website content display, accurate and unified number presentation is crucial for user experience.For example, displaying product prices on e-commerce websites or presenting statistical percentages in data reports may result in excessively long decimal places if floating-point numbers are displayed without processing, which may appear unprofessional and untidy.AnQi CMS as an efficient content management system provides powerful template functions, among which the `stringformat` filter is a powerful tool to solve this problem.

2025-11-08

What is the practical use of the `dump` filter in AnQi CMS template debugging?

During the development and maintenance of Anqi CMS templates, we often encounter situations where some data cannot be displayed correctly or the variable structure does not match the expected one.How can one quickly and effectively find the source of the problem, which is a challenge facing every template developer.Fortunately, AnQi CMS provides an extremely useful tool—the `dump` filter, which can help us penetrate the true appearance of variables in the template like X-ray.What is the `dump` filter?

2025-11-08

How to customize the title display format of AnQi CMS article detail page?

The secret to flexibly customizing the CMS article detail page title display formatIt not only affects the identification of users in browser tabs and favorites, but is also one of the key elements of search engine optimization (SEO).A clear, attractive, and well-formatted title that can effectively improve the click-through rate of the article and the professional image of the website.

2025-11-08

How to call and display custom parameter fields of articles in the Anqi CMS template?

In AnQi CMS, the custom parameter field of the article is an important manifestation of its core feature of 'flexible content model'.It allows us to define unique additional attributes for different types of content (such as articles, products), greatly enhancing the expressiveness of content and the customization capabilities of the website.Imagine if your website needs to display product details, in addition to the general information such as title, content, and images, you may also need specific parameters such as 'model number', 'color', 'storage capacity', and so on.These are the places where custom parameter fields take effect.

2025-11-08

How to display article thumbnails in the Anqi CMS article list?

## How to Display Thumbnails Gracefully in AnQi CMS Article List Visual appeal of the article list page is crucial in website operation.A carefully selected or automatically generated thumbnail that can quickly catch the visitor's attention, convey the theme of the article, and thus improve click-through rate and optimize user experience.Our AnQi CMS provides flexible and powerful functions, helping us easily display article thumbnails in the article list.

2025-11-08

How to display hot articles on the AnQiCMS homepage based on article views?

On AnQiCMS, the homepage is usually the important entry point for visitors to understand the website content and quickly obtain information.Effectively display popular articles, not only to attract users' attention, improve content exposure, but also effectively enhance the user experience of the website and PV (page views).AnQiCMS with its flexible template tags and built-in features makes this operation very simple and intuitive.

2025-11-08