How to sort the document list of Anqi CMS by views or publish time?

Calendar 👁️ 70

How to effectively organize and present content in website construction and operation is the key to improving user experience and content discovery efficiency.For friends using AnQiCMS, it is a very practical feature to flexibly sort the document list.Whether it is to allow visitors to see the most popular articles first or the latest updates, AnQiCMS provides a simple and powerful way to achieve this.

Generally, when we want to display a series of documents, such as blog posts, product introductions, or news lists, we would like them to be arranged in a specific logical order.The most common requirement is to sort documents by the number of views (popularity) or publication time (newest).Aqin CMS provides special template tags for this, allowing you to easily implement these sorting logic on the website front-end.

Core Tool:archiveListDocument List Tags

In the template system of Anqi CMS,archiveListThe tag is a core tool for retrieving document lists. It is powerful and can be used to filter, limit, and sort the documents you want to display with various parameters.All sorting logic will be centered around this tag'sorderParameter expansion.

The basic usage form of this tag is as follows:

{% archiveList 变量名称 with 参数="值" %}
    {# 在这里循环显示文档内容 #}
{% endarchiveList %}

Among them,变量名称Can be a custom name, for examplearchivesUsed to refer to each document in a loop.参数andIs the key to controlling the behavior of the document list.

Sort option one: Sort by views (Views)

If your goal is to let visitors see the most popular and most read content on the website at a glance, then sorting in descending order of views is a very good choice. Anqi CMS'sarchiveListTags providedviews descThis parameter value is used to implement this function.descMeans descending order, that is, from high to low.

For example, if you want to display the top 10 viewed articles on your website homepage or specific category page, you can write the template code like this:

<div class="most-popular-articles">
    <h2>热门文章</h2>
    <ul>
        {% archiveList archives with type="list" order="views desc" limit="10" %}
            {% for item in archives %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    <h3>{{ item.Title }}</h3>
                    <p>浏览量:{{ item.Views }}</p>
                </a>
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In this code block:

  • type="list"Indicates that we are getting a regular list, not a list for pagination.
  • order="views desc"Explicitly specifies sorting by the document's view count (Views) in descending order.
  • limit="10"It limited the display to only the top 10 most popular articles.
  • Inforinside the loop,item.LinkGet the document link,item.TitleGet the document title,item.ViewsIt shows the document's page views.

With such settings, your website will dynamically display the content that most attracts the attention of visitors.

The second sorting method: Sort by publish time (CreatedTime)

For news updates, latest product releases, or time-sensitive content, we tend to display them in the order from new to old based on the publication time, so that visitors can stay informed about the latest information. In Anqi CMS, the documentsIdIt is usually automatically incremented, therefore sorted according toid descThis can effectively achieve the sorting from new to old by publication time.

To display the latest documents, you can modify it in this wayarchiveListTags:

<div class="latest-articles">
    <h2>最新动态</h2>
    <ul>
        {% archiveList archives with type="list" order="id desc" limit="5" %}
            {% for item in archives %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    <h3>{{ item.Title }}</h3>
                    <p>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02 15:04") }}</p>
                </a>
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Here:

  • order="id desc"Tell the system to sort documents by ID in descending order, as IDs are usually assigned in the order of document creation, which is equivalent to sorting by the latest release time.
  • item.CreatedTimeGet the creation time of the document, which is a timestamp.
  • stampToDate(item.CreatedTime, "2006-01-02 15:04")It is a very useful helper function, which can format the timestamp into a date and time string that is easier for us to read."2006-01-02 15:04"It is the time formatting standard in Go language, you can adjust it as needed to display year-month-date, hour:minute, and other information.

Combined with pagination function usage.

When your document quantity is very large, simply displaying a list is not enough, and pagination features are usually required.archiveListin the tag, you just need totypethe parameter topage, then combinepaginationtag to achieve.

For example, a list of the latest articles with pagination can be implemented in this way:

<div class="paginated-latest-articles">
    <h2>所有文章</h2>
    <ul>
        {% archiveList archives with type="page" order="id desc" limit="10" %}
            {% for item in archives %}
            <li>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    <h3>{{ item.Title }}</h3>
                    <p>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>
                </a>
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>

    {# 分页代码 #}
    <div class="pagination-controls">
        {% pagination pages with show="5" %}
            {% if pages.PrevPage %}<a href="{{ pages.PrevPage.Link }}">上一页</a>{% endif %}
            {% for page in pages.Pages %}
                <a href="{{ page.Link }}" class="{% if page.IsCurrent %}active{% endif %}">{{ page.Name }}</a>
            {% endfor %}
            {% if pages.NextPage %}<a href="{{ pages.NextPage.Link }}">下一页</a>{% endif %}
        {% endpagination %}
    </div>
</div>

Here, type="page"TellarchiveListThe label indicates that this is a list that requires pagination and:limit="10"defines that 10 documents are displayed per page. Following that,paginationTags will automatically generate page number links, convenient for visitors to browse all pages.

Summarize the operation steps

Sort the document list in Anqi CMS by page views or publish time, just follow these steps:

  1. Confirm the template file to be modifiedThis is usually the homepage template of the website (index/index.htmlcategory list page template ({模型table}/list.htmlor other parts containing document lists.
  2. FindarchiveListTag: Locate the code block responsible for displaying the document list in the template file.{% archiveList ... %}code block."),
  3. AdjustmentorderParameter:
    • To pressView count from high to lowSort, please setorderthe parameter toorder="views desc".
    • To pressPublished time from new to oldSort, please setorderthe parameter toorder="id desc".
  4. Save and update cacheSave the template file, if the website has enabled caching, remember to update the system cache in the background so that the new sorting rules take effect.

The template tag design of Anqi CMS makes content sorting intuitive and easy to use. By simply adjusting the parameters, your website content can be presented in the most suitable way for visitors, greatly enhancing the practicality and user experience of the website.


Frequently Asked Questions (FAQ)

  1. Ask: Can I sort the document in ascending order (asc) besides descending order (desc)?Of course you can. Inorderthe parameters, besidesdesc(descending order), you can also useasc(Ascending). For example,order="views asc"It will be sorted from low to high by views, whileorder="id asc"it will be sorted by the earliest published documents.

  2. Question:order="id desc"andorder="CreatedTime desc"What is the difference, which one should I choose to sort by publication time?Answer: In AnQi CMS,orderthe parameter supports directlyid descto sort by document ID in descending order. Since the document ID is usually a unique and incrementing identifier automatically assigned when the system is created, thereforeid descEffectively realize the sorting from new to old by publishing time.CreatedTimeThe field itself stores the publishing time.

Related articles

How can AnQi CMS display a list of documents under a specified category and perform pagination?

AnQiCMS (AnQiCMS) with its flexible template mechanism and powerful content management features makes the display of website content very simple and efficient.For many websites, clearly displaying content by category and providing convenient pagination navigation is the key to improving user experience and optimizing search engine rankings.Let's learn together how to easily implement document list display and pagination functions under specified categories in Anqi CMS.### Flexible configuration, control content display Anqi CMS template system uses syntax similar to Django template engine

2025-11-08

How to display content from a specific site by using label parameters in a multi-site environment?

When using AnQiCMS for website management, the multi-site feature undoubtedly brings great convenience to users with multiple brands, sub-sites, or content branches.It allows us to efficiently manage multiple independent websites on a unified backend.However, in actual operation, we sometimes encounter a specific requirement: to display the content of another specific site on a site.For example, the main site wants to reference some of the latest articles from the child site, or a specific thematic site wants to display product information from another cooperative site.At this moment, 'How to set up an environment across multiple sites'

2025-11-08

How to troubleshoot when the AnQiCMS program is upgraded and the front-end page does not update?

How to troubleshoot when the front page does not update after the AnQiCMS program upgrade? When you eagerly upgraded the AnQiCMS program, expecting new features and optimizations to immediately appear on your website, only to find that the front page remained unchanged and stuck in the old version, that feeling is indeed quite crazy.Don't worry, this is usually not a big problem, mostly due to caching or program loading mechanisms.Today we will work together to investigate in detail and see how to make your website's front-end look brand new.

2025-11-08

How to implement content parameter filtering and dynamically adjust the list display results in AnQiCMS?

In a content management system, allowing users to quickly find the information they need according to their own needs is the key to enhancing the website experience and content value.AnQiCMS provides a powerful custom content model and flexible template tags, which helps us easily implement content parameter filtering, dynamically adjust the display results of the list, and greatly enhance the interaction and user-friendliness of the website content.This article will discuss in detail how to use these features in AnQiCMS, from backend configuration to frontend display, and step by step to implement content parameter filtering.

2025-11-08

How to filter document lists in AnQi CMS based on recommended attributes (such as headlines, recommendations)?

AnQi CMS as an efficient content management system, provides rich functions to help operators manage and display website content.Among the "recommended properties" feature is a very practical tool, which allows us to flexibly mark documents, thereby realizing dynamic filtering and display of specific content in different areas of the website.This article will discuss in detail how to use recommended attributes to filter document lists in AnQi CMS, making the website content more dynamic and attractive.

2025-11-08

How to exclude specific category content from the document list?

In website operation, we often need to flexibly control the display of content.For example, you may want to display the latest articles on the homepage, but not include a specific category such as "internal notices" or "archived content";Or in a product list, you want to exclude those categories that are "discontinued" or "internal testing", to keep the user interface simple and clear. A security CMS provides very convenient and powerful functions to meet such needs.By cleverly using the template tag `archiveList`

2025-11-08

How to achieve accurate display of in-site search results in Aiqi CMS?

The importance of on-site search functionality in daily website operation is self-evident.It is not only a bridge for users to quickly find the information they need, but also a key link to improve user experience, extend visit duration, and even promote conversion.If a user enters a keyword and gets a bunch of irrelevant results, they are likely to leave quickly.Therefore, how to achieve accurate display of in-site search results in AnQiCMS is a topic that every content operator should delve into.AnQiCMS is a system specially designed for content management, with a powerful and flexible search mechanism and content organization capabilities

2025-11-08

How to retrieve and display the complete content and all fields of a single document?

One of the core values of a content management system is the ability to flexibly define and present various types of content.For users of AnQiCMS, whether it is to display a detailed article, a product page, or a custom data entry, how to efficiently obtain its complete content and all associated fields is the key to front-end template development and content presentation.Today, let's delve into how to easily control the acquisition and display of individual document content in AnQiCMS using this '万能钥匙' template tag.

2025-11-08