How does AnQiCMS display the latest article list and its publication time on the front end?

Calendar 👁️ 60

In website operation, displaying the latest released content to visitors in a timely manner can not only effectively improve user experience but also enhance the activity of the website.AnQiCMS (AnQiCMS) provides an intuitive and powerful template tag feature, allowing you to easily display the latest article list and its publication time on the website front page.

Understanding the article display mechanism of AnQi CMS

The AnQi CMS uses template tags to call and display website data.This means that you do not need to write complex backend code, just use predefined tags in the template file, and the system can automatically extract and present the required content from the database.For the article list, we mainly usearchiveListTags andstampToDateTime formatting tags.

Core Steps: Call the latest article list and publish time

To display the latest article list and their publish time on the front page, we can follow the following simple steps:

  1. Determine the source and sorting method of the articleFirstly, we need to tell Anqi CMS which articles to display and how to sort them.archiveListTags are the key to obtaining the article list.

    • Specify content model (moduleId)In Anqi CMS, articles, products, and other items belong to different 'content models'. Usually, the content model ID for articles is 1. Therefore, you can setmoduleId="1"Make sure we get the article.
    • Specify sorting (order): To display the latest articles, we need to sort by the article's publishing time (usually corresponding to the ID in the database or the creation time) in descending order.order="id desc"It is a commonly used method, which sorts articles in descending order by article ID. Since IDs are incremented, this is usually equivalent to sorting by publishing time from new to old.
    • Limit the number of displayed items (limit): You can limit the number of articles displayed in the list according to your page design, for examplelimit="10"It will display the latest 10 articles.
    • List type (type): For regular list display, it is usually set totype="list".
  2. UsearchiveListLabel to retrieve dataIn your template file (for example, the homepage of the websiteindex.htmlor the article list pagearchive/list.htmletc), usingarchiveListtag to wrap the structure of your article list.

    {% archiveList archives with moduleId="1" order="id desc" limit="10" type="list" %}
        {# 文章列表将在这里循环显示 #}
    {% endarchiveList %}
    

    Here, we assign the obtained article list to a variable namedarchives.

  3. Loop to output the article title, link, and publication time archiveListThe tag will return an array of article objects, you can useforLoop through this array and extract the details of each article.

    • Article title: Pass{{item.Title}}To display the article title.
    • Article link: Pass{{item.Link}}To get the detail page link of the article.
    • Release Time: The creation time of the article is stored initem.CreatedTimefield, which is a timestamp. To display it in a readable date format, we need to usestampToDatethe tag for formatting, for example{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}Will format it as "Year-Month-Day Hour:Minute".

Complete code example:

Place the following code snippet in the template location where you want to display the latest article list, such as a block or sidebar file on the homepage:

<div class="latest-articles-list">
    <h3>最新文章</h3>
    <ul>
        {% archiveList archives with moduleId="1" order="id desc" limit="10" type="list" %}
            {% for item in archives %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    <span class="article-title">{{ item.Title }}</span>
                    <span class="article-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span> {# 显示年-月-日 #}
                </a>
            </li>
            {% empty %}
            <li>暂无最新文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

This code will generate an unordered list containing the latest 10 articles.Each article displays its title and publication date. If there are no articles, it will display 'No latest articles available.'The prompt.

Location to place the template code.

This code can be flexibly placed in any template file of your website. For example:

  • Home page (index.html): is usually used to display the featured content of the website.
  • Sidebar (partial/sidebar.html)In a blog or information site, the sidebar is often used to display popular articles, the latest articles, and so on.
  • Specific category page (archive/list.html): You can highlight the latest articles under a category at the top or bottom of a category page.

By following these steps, you can easily display the latest article list and its publication time on the front end of the Anqi CMS-built website, providing fresh and valuable content to visitors.


Frequently Asked Questions (FAQ)

  1. Q: How do I display the latest articles under a specific category?A: You canarchiveListthe tag withcategoryIdParameters are used to specify the article category. For example, if your category ID is 5, you can write it like this:{% archiveList archives with moduleId="1" categoryId="5" order="id desc" limit="10" type="list" %}.

  2. Q: The display format of the publish time is not satisfactory, how to adjust?A:stampToDateThe second parameter of the tag is the format string. You can adjust it as needed. For example,"2006年01月02日"It will display as "2006-01-02""15:04"It will display as "15:04" (time only). Please refer to the Go language formatting rules for setting it.

  3. Q: If the article list is long, I need a pagination feature, how should I implement it?A: If you need to display pagination, you can usearchiveListlabel'stypethe parameter to"page", then combinepaginationtags together. For example:{% archiveList archives with moduleId="1" order="id desc" limit="10" type="page" %}… (article list loop) …{% pagination pages with show="5" %}(pagination link){% endpagination %}Pagination navigation will be generated below the article list.

Related articles

How to accurately display the field data of a custom content model on the front-end page?

In AnQiCMS, we often need to create various types of content according to the actual needs of the website.AnQiCMS's powerful custom content model feature is designed to meet this flexibility.It allows us to define dedicated fields for different types of content (such as articles, products, cases, etc.), thus enabling more precise management and display of information.How can we accurately call and display these custom field data on the website's front page?

2025-11-08

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

AnQi CMS has excellent flexibility in content display, especially for article detail pages, it provides multi-level customization options, allowing us to finely control the layout of content display according to specific needs, whether it is for the entire model, specific categories, or an independent article.This not only involves adjustments in appearance, but also includes in-depth customization of the page content structure and information presentation.

2025-11-08

How do Sitemap, Robots.txt, and other advanced SEO tools in AnQiCMS affect the visibility of website content in search engines?

During the journey of website operation, we all hope that our content can be discovered by more potential users.And the search engine is undoubtedly the most important bridge connecting websites to users.To ensure that this bridge is unobstructed, our website needs to communicate effectively with search engines.

2025-11-08

How to configure the pseudo-static URL rules in AnQiCMS to optimize the display structure of website content links?

The importance of link structure in website operation is self-evident.A clear and meaningful URL not only enhances user experience, but also makes it easier for visitors to understand the content of the page, and is a key factor in Search Engine Optimization (SEO).Disorganized, dynamic URLs with a large number of parameters often make it difficult for search engine spiders to crawl and are not conducive to the transmission of keyword weights.Therefore, converting dynamic URLs to static forms is a common choice in modern website construction.AnQiCMS (AnQiCMS) knows this, built-in powerful static URL configuration function

2025-11-08

How to implement user-friendly pagination navigation display for the article list?

The article list is the core display area of the website content, and its user experience directly affects the visitor's stay time and willingness to revisit.When the number of articles is large, a reasonable page navigation design is particularly important.AnQiCMS (AnQiCMS) provides powerful and flexible template tags to help us easily implement user-friendly article list pagination functions, making content management and display more efficient.

2025-11-08

How to filter and display related article lists on the front page according to the specified category ID?

In Anqi CMS, it is actually very simple to filter and display a list of related articles on the front page according to the category ID!The AnQi CMS, with its efficient and flexible features, makes content management and display easy.No matter if you are running a corporate website, an industry information station, or a personal blog, you may encounter the need to display a list of articles according to a specific category.For example, display articles from a certain "Hot Recommendation" category on the homepage, or showcase specific "Product Cases" on a special topic page.Today, let's talk about how to accurately implement this function in the Anqi CMS front-end template.###

2025-11-08

How to display the links to the previous and next articles at the bottom of the article detail page?

In website content operation, improving user reading experience is a key link.After a reader has finished browsing an excellent article, if they can immediately see a link to the next related or sequential article, it will undoubtedly greatly increase the likelihood that they will continue to stay on the website.This design not only optimizes the user experience, helps guide users to delve deeper into the website's content, but also effectively reduces the bounce rate and enhances the website's SEO performance, allowing search engines to better understand the structure of your website's content.

2025-11-08

How to aggregate and display a list of selected articles under multiple categories on a single page?

In website operation, we often encounter such needs: on the homepage or a special topic page, we can display selected articles from different categories, which can enrich the page content and guide users to discover more interesting information.AnQiCMS provides very flexible and powerful features, allowing us to easily achieve this goal without complex programming knowledge.

2025-11-08