How to implement sorting of the document list by views or publication time using the `archiveList` tag?

Calendar 👁️ 56

As an experienced website operation expert, I deeply understand that the core value of a content management system (CMS) lies in its flexibility and the efficiency of content presentation.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture in the Go language and a rich set of features.Today, let's delve deeply into a feature that is extremely commonly used in content operation: how to make use ofarchiveListThe tag implements sorting of the document list by view count or publish time.

Content sorting, it seems simple, but it actually contains profound operational strategies.In order to highlight the latest news or recommend popular content, precise sorting can greatly enhance user experience and content access efficiency.In AnQiCMS,archiveListThe tag is the key tool to achieve this goal.

Get to know AnQiCMS.archiveListTag

First, let's briefly review.archiveListThe label is designed to retrieve and display document lists from the AnQiCMS database, whether articles, products, or documents under other custom content models.Its strength lies in its rich parameters, allowing you to precisely control the range, quantity, and most importantly—the sorting method of the content displayed.

In the AnQiCMS template files, you will see syntax similar to the Django template engine,archiveListtags are usually in the form of{% archiveList archives with ... %}such as this form, among whicharchivesIt is the variable name you define for the document list obtainedwithand the following is various control parameters

The core secret:orderThe magic of parameters

To achieve sorting by page views or publication time, we mainly rely onarchiveListin the labelorderThe parameter is the 'wand' that controls the order of content presentation in AnQiCMS. Its basic syntax isorder="字段名 排序方向".

1. Sort by publication time: let the latest content stand out

On websites where content is updated frequently, the 'Latest Articles' are often the key to attracting users to revisit.AnQiCMS usually associates the creation time of the document with the automatically generated ID (primary key), so the larger the ID, the later the publication time is usually.

To arrange the document list from new to old by publication time, you can useorder="id desc":

{% archiveList latestArticles with categoryId="1" limit="10" order="id desc" %}
    {% for item in latestArticles %}
    <li>
        <a href="{{item.Link}}">{{item.Title}}</a>
        <span>发布于: {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
    </li>
    {% endfor %}
{% endarchiveList %}

In this code block:

  • latestArticlesis the variable name we define to store the list of the latest articles.
  • categoryId="1"Specified to only retrieve articles under category ID 1 (you can modify it according to your actual situation).
  • limit="10"Indicates that we want to display the latest 10 articles.
  • order="id desc"It is the core, it tells AnQiCMS to sort by document ID in descending order (descwhich means from large to small), so that the latest released content is displayed at the top.
  • {{stampToDate(item.CreatedTime, "2006-01-02")}}It is used to set the document creation timestampCreatedTimeFormatted into a readable date format, for example “2023-10-26”. AnQiCMS'sstampToDateThe tag is very useful, it follows the Go language's time formatting rules,"2006-01-02"which means年-月-日.

If you need to sort by publish time from old to new, justdescchanged toasc, that isorder="id asc".

2. Sort by views: Discover the most popular content

Understanding user interests and recommending them to more people is an effective means of increasing website activity.By sorting the document list by page views, you can easily create modules such as "Hot Articles" and "Reading Rankings" and more.

To sort the document list by views from highest to lowest, you can useorder="views desc":

{% archiveList hotArticles with categoryId="1" limit="5" order="views desc" %}
    {% for item in hotArticles %}
    <li>
        <a href="{{item.Link}}">{{item.Title}}</a>
        <span>浏览量: {{item.Views}}</span>
    </li>
    {% endfor %}
{% endarchiveList %}

This code:

  • hotArticlesStored the article list sorted by views.
  • categoryId="1"andlimit="5"The usage is similar to the previous example.
  • order="views desc"It is crucial, it indicates that AnQiCMS sorts the fields according to the document'sViewsfield in descending order to ensure that the documents with the highest number of views are at the top.
  • {{item.Views}}It directly displays the document's view count.

Similarly, if you want to display the document with the least views, you candescchanged toasc, that isorder="views asc".

Combine it with practical use to enhance content operation efficiency

Mastering these two sorting methods, you can apply them flexibly to various operational scenarios:

  • The "Latest News" or "This Week's Hot" area on the homepage:Dynamically display the latest or most popular content to maintain the vitality of the website.
  • Sidebar "Reading Rank":Guide users to discover more interesting content and extend their stay time.
  • Content aggregation page:Provide multiple sorting perspectives for content under specific themes or categories to meet the needs of different users.
  • SEO optimization:Combine browsing data to analyze which content is more popular with users and optimize the content strategy accordingly.

By flexible applicationorderParameter, of AnQiCMS.archiveListThe tag provides you with great freedom in content presentation. It not only makes your website content more attractive, but also greatly simplifies the daily work of content operation, allowing you to focus more energy on creating high-quality content.

Frequently Asked Questions (FAQ)

Q1:order="id desc"andorder="CreatedTime desc"What are the differences in AnQiCMS?A1: In AnQiCMS, the document'sidis usually auto-incrementing, thereforeidsize directly reflects the order of document creation. So,order="id desc"In fact, it has the same effect as sorting by creation time from new to old, and is more efficient. AlthougharchiveListthe tags returned byitemincludingCreatedTimefield, butorderthe parameter supports directlyidandviewsand other keyword fields for sorting,CreatedTimeis mainly used for display rather than direct sorting.

Q2: Can I sort by multiple conditions at the same time, such as sorting by views first and then by publish time?A2: AnQiCMS'archiveListlabel'sorderParameters usually accept a primary sorting rule. According to the document example, it listsorder="id desc"/order="views desc"Independent options. Although in the documentdesign-tag.mdappeared in the exampleorder="id desc|views desc"This writing may imply a priority or alternative sorting logic.But in practice, for clarity, we usually choose the most important sorting dimension.If you have more complex sorting requirements, you may need to combine backend logic or further review the deeper documentation of AnQiCMS to confirm the specific support methods and syntax for multi-level sorting.

Q3: How to display more document information in the sorted list, such as category names or custom fields?A3: InarchiveListlabel'sforthe loop,itemThe variable represents the current document object, you can directly{{item.字段名}}access its properties, for example,{{item.Title}}/{{item.Link}}/{{item.Views}}. To access the category name of the document, you can{{ categoryDetail with name="Title" id=item.CategoryId }}Nested tags to obtain. For example, if the document model has custom fields,authoryou can also use{{item.author}}or more generalarchiveParamstags to call and display this additional information.

Related articles

How to use the `archiveList` tag to get documents with specific recommended attributes (such as "Top Stories" or "Slideshow")?

As an experienced website operations expert, I am well aware of the core value of a content management system (CMS) in terms of its flexibility and content scheduling capabilities.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and rich features, providing strong support for content operations.Today, let's delve into a very practical scenario in content operation: how to accurately obtain and display documents with specific recommendation attributes using the `archiveList` tag, such as the website's 'headlines' news or important content for the 'slideshow' carousel.

2025-11-06

How to exclude documents of a specific category in `archiveList` to display accurate content?

As an experienced website operations expert, I am well aware of the importance of accurate content display for user experience and website operation efficiency.In a content management system, we often encounter the need to exclude certain specific categories of documents when generating article lists, in order to ensure the relevance and focus of the content.AnQiCMS (AnQiCMS) is an efficient and flexible content management tool that provides us with a very convenient solution.

2025-11-06

How to filter and display documents based on multiple category IDs for the `archiveList` tag?

As an experienced website operations expert, I fully understand that the flexibility of a content management system is crucial for efficient operations.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template tag system.Today, let's delve deeply into a very practical feature: how to use the `archiveList` tag to filter and display documents based on multiple category IDs, thereby creating more targeted and attractive content modules.

2025-11-06

How to use the `archiveList` tag of AnQiCMS to get the document list under a specified content model?

AnQiCMS Content Management: The secret to accurately obtaining the document list with the `archiveList` tag As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its ability to organize and display content.In the AnQiCMS, this efficient and flexible Go language content management system, the `archiveList` tag is undoubtedly a powerful weapon in the content display process.It is not just a simple content call tag, but also a key bridge connecting your website content model with the front-end display logic.

2025-11-06

How to set the display quantity and offset for the `archiveList` tag in AnQiCMS to achieve pagination?

As an experienced website operations expert, I know that an efficient and flexible list display method is crucial for user experience and website performance.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template tag system.Today, let's delve into how to cleverly set the display quantity and offset using the AnQiCMS `archiveList` tag to achieve a smooth pagination effect.

2025-11-06

How to use the `archiveList` tag to perform keyword search (using `q` parameter) to filter documents on the frontend page?

## Unlock AnQiCMS: Use the `archiveList` tag to implement keyword search and content filtering on the front-end page As an experienced website operations expert, I am well aware of the importance of an efficient and flexible content management system for enterprises.AnQiCMS, this system developed based on the Go language, with its excellent performance and rich features, is becoming the preferred choice for an increasing number of small and medium-sized enterprises and content operation teams.In today's era of information explosion, whether users can quickly find the content they need is directly related to the user experience and conversion rate of the website.

2025-11-06

How to retrieve related content of the current document using the `archiveList` tag's `type="related"` mode?

As an experienced website operations expert, I am very happy to delve deeply into the `archiveList` tag in AnQiCMS with the `type="related"` mode, which plays a crucial role in content operations and can effectively improve user experience and the website's SEO performance. --- ## In-depth Analysis of AnQiCMS's `archiveList` Tag: How to intelligently retrieve related content and enhance user experience In such an efficient and customizable content management system as AnQiCMS

2025-11-06

How to call the document data of different sites (`siteId`) through the `archiveList` tag?

As an experienced website operations expert, I fully understand the challenges you may encounter when managing multi-site content.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful multi-site management capabilities.Today, let's delve into how to use the `archiveList` tag and its core parameter `siteId` to easily implement cross-site document data calls.

2025-11-06