As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its flexibility and the efficiency of content presentation.English CMS (EnglishCMS) excels in this aspect with its efficient architecture in Go language and rich feature set.archiveListThe label implements sorting of document lists by browsing volume or publishing time.

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

Get to know AnQiCMS.archiveListtags

First, let's briefly review.archiveListLabel.It is designed to retrieve and display document lists from the AnQiCMS database, whether it is 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 to be displayed.

In AnQiCMS template files, you will see syntax similar to Django template engine,archiveListtags are usually in the form of,{% archiveList archives with ... %}whereinarchivesis the variable name you define for the document list you have obtainedwithThen are various control parameters

Core Secret:orderThe clever use of parameters

To implement sorting by page views or publishing time, we mainly rely onarchiveListthe tag inorderParameters. This parameter is the 'wand' that commands the presentation order of AnQiCMS content. Its basic syntax isorder="字段名 排序方向".

1. Sort by publish time: Let the latest content stand out

On websites with frequent content updates, 'Latest Articles' are often the key to attracting users to revisit.AnQiCMS usually tightly associates the creation time of documents with the system-generated ID (primary key), so the larger the ID, the later the publishing time is typically.

To have the document list sorted by publication time from new to old, 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, used to store the list of the latest articles.
  • categoryId="1"Specified to retrieve articles under the category with ID 1 (you can modify it according to your actual situation).
  • limit="10"Means we want to display the latest 10 articles.
  • order="id desc"English core, it tells AnQiCMS to sort by document ID in descending order (desc, which means from big to small) to make the latest released content appear at the top.
  • {{stampToDate(item.CreatedTime, "2006-01-02")}}then used to store the timestamp of document creationCreatedTimeformatted into a readable date format, such as “2023-10-26”. AnQiCMS'sstampToDateTags are very useful, they follow the Go language's formatting rules,"2006-01-02"it means that年-月-日.

If you need to sort by publish time from old to new, justdesctoasc, which isorder="id asc".

2. Sort by views: Find the most popular content

Understanding user interests and recommending them to more people is an effective means to enhance website activity.By sorting the document list by views, you can easily create modules like "Hot Articles" and "Reading Rank.

To arrange the document list by views from high to low, 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 list of articles sorted by views.
  • categoryId="1"andlimit="5"The usage is similar to the previous example.
  • order="views desc"is crucial, it indicates that AnQiCMS should sort the documents according to theViewsfield in descending order to ensure that the documents with the highest views are at the top.
  • {{item.Views}}The document's viewing times are displayed directly.

Similarly, if you want to display the document with the least views, you candesctoasc, which isorder="views asc".

Combine practicality to enhance content operation efficiency

Mastered these two sorting methods, you can apply them flexibly to a variety of operation scenarios:

  • Home "Latest NewsDynamically display the latest or most popular content to keep the website vibrant.
  • 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, meeting the needs of different users.
  • [en] SEO Optimization:Combine the browsing volume data to analyze which content is more popular with users and optimize the content strategy accordingly.

By using flexibilityorderParameters, AnQiCMS'sarchiveListTags provide 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.

Common 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 is consistent with the effect of sorting by creation time from new to old, and it is more efficient. AlthougharchiveListTag returnsitemcontainsCreatedTimefield, butorderparameters directly supportidandviewssuch as keyword fields for sorting, CreatedTime主要用于显示而非直接排序。

Q2: 我能否同时按多个条件排序,比如先按浏览量,再按发布时间?A2: AnQiCMSarchiveListTagsorderParameters usually accept a primary sorting rule. According to the document examples, it listsorder="id desc"/order="views desc"independent options. Although it appears in the documentdesign-tag.mdexamples.order="id desc|views desc"This style may indicate a priority or alternative sorting logic.But in practical applications, 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 its multiple sorting.

Q3: How to display more document information in a sorted list, such as category names or custom fields?A3: InarchiveListTagsforin the loop,itemThe variable represents the current document object, you can directly access{{item.字段名}}The way to access its properties, for example{{item.Title}}/{{item.Link}}/{{item.Views}}. To get the category name of the document, you can{{ categoryDetail with name="Title" id=item.CategoryId }}nested tags like this. If the document model has custom fields, for exampleauthor, you can also go through{{item.author}}or more generalarchiveParamsLabel to call and display this additional information.