How to display the article list according to different sorting rules (such as latest, views, custom sorting)?

Calendar 👁️ 73

Managing website content in Anqi CMS, flexibly controlling the display order of article lists is crucial for improving user experience and content distribution efficiency.Whether you want the latest content to appear immediately in front of visitors, highlight the most popular articles, or manually adjust the layout of articles according to specific operational strategies, Anqi CMS provides a simple and powerful way to meet these needs.

One of the core advantages of AnQi CMS is its intuitive and feature-rich template tag system. When dealing with the display of article lists, we mainly usearchiveListThis tag. It is like a multifunctional conductor, able to present the content of the article in various sorting methods on the website page according to the instructions provided.

Flexible applicationarchiveListLabel: The conductor of content display

To display a list of articles, we first need to understandarchiveListThe basic structure of the label. It is usually wrapped in aforloop to iterate and display multiple articles:

{% archiveList archives with type="list" limit="10" order="id desc" %}
    {% for item in archives %}
        <div class="article-item">
            <a href="{{item.Link}}">
                <h3>{{item.Title}}</h3>
            </a>
            <p>{{item.Description}}</p>
            <p>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}} | 浏览量:{{item.Views}}</p>
        </div>
    {% empty %}
        <p>暂时没有文章内容。</p>
    {% endfor %}
{% endarchiveList %}

In this code block,archiveList archives with ...Defined the article data we want to retrieve and named itarchives.type="list"Indicates that we want to retrieve a fixed list rather than a paginated list.limit="10"It controls the number of articles displayed each time. What is most critical isorderThis parameter determines the sorting rules of the articles.

Set the sorting rules according to different needs.

The AnQi CMS provides several commonly used sorting methods, allowing us to easily handle various content operation scenarios.

1. Latest article sorting: Keep the content fresh.

Visitors to the website often want to see the latest information. To sort the 'Latest Articles', we can use the article ID or creation time.In Anqi CMS, article IDs are typically incremented, so sorting by ID in descending order can effectively display the latest published articles.

We just need toarchiveListSet in the labelorder="id desc",descThe articles are displayed in descending order, meaning the articles with higher (more recent) ID values are shown first.

{% archiveList archives with type="list" limit="10" order="id desc" %}
    {% for item in archives %}
        <div class="latest-article">
            <a href="{{item.Link}}">
                <h4>{{item.Title}}</h4>
            </a>
            <small>发布于:{{stampToDate(item.CreatedTime, "2006年01月02日")}}</small>
        </div>
    {% endfor %}
{% endarchiveList %}

This code will fetch the latest 10 articles and display them in reverse chronological order of their publication time.

2. View count sorting: highlight popular content

If the goal of the website is to highlight the most popular or most viewed articles to attract more user attention, then sorting by view count is an ideal choice.The AnQi CMS can automatically record the number of views for each article.

By settingorder="views desc"We can easily place the articles with the highest view count at the top of the list.

{% archiveList archives with type="list" limit="5" order="views desc" %}
    {% for item in archives %}
        <div class="popular-article">
            <a href="{{item.Link}}">
                <h5>{{item.Title}}</h5>
            </a>
            <span>阅读量:{{item.Views}}次</span>
        </div>
    {% endfor %}
{% endarchiveList %}

This code will display the top 5 articles with the highest number of views on the website, allowing visitors to see the hot content at a glance.

3. Custom sorting: Flexibly control the order of articles.

In certain special cases, we may need to manually adjust the display order of articles based on factors such as operational activities, thematic recommendations, etc.The AnQi CMS provides a feature for custom sorting in the backend, allowing us to set a 'sort value' for articles in the article editing interface.

Let the list be displayed according to this custom sorting value, we canarchiveListUsed in tagsorder="sort desc"(orsort ascIt depends on whether you want the sorting value to be in front or not, usually the larger sorting value will be in front, so we usedesc)

{% archiveList archives with type="list" limit="8" order="sort desc" %}
    {% for item in archives %}
        <div class="custom-sorted-article">
            <a href="{{item.Link}}">
                <h6>{{item.Title}}</h6>
            </a>
            <small>更新于:{{stampToDate(item.UpdatedTime, "2006-01-02 15:04")}}</small>
        </div>
    {% endfor %}
{% endarchiveList %}

In this way, the display order of the articles will completely follow the sorting value we set in the background.

Combined with other filtering conditions, create a more refined list.

archiveListThe strength of tags lies in their ability to be combined with other parameters to create more refined article lists. For example:

  • categoryId="1":Only display articles under specific categories.
  • flag="c":Only display articles marked as "recommended" (cThe recommended attribute letter is "recommended").
  • q="关键词":Display articles with specific keywords in the title (often used on search result pages).
  • limit="5,10":Start from the 5th article and display 10 articles (used to skip the first few recommended contents).

These parameters can be combined withorderto use parameters, for examplecategoryId="1" order="id desc"Indicates displaying the latest articles under category ID 1.

Summary

Of Security CMSarchiveListFlexible tags and theirorderParameters provide us with powerful tools to control the display style of the website article list.Whether it is to pursue the freshness of content, emphasize hot topics, or carry out refined content operation, Anqi CMS can help us easily achieve it, thus better attracting and retaining visitors.By mastering these sorting rules, we can dynamically adjust the content presentation according to the website's strategy and user needs, keeping the website always vibrant.


Frequently Asked Questions (FAQ)

Q1: How to display a list of articles with different sorting rules on a single page?

A1:You can use it multiple times on the same pagearchiveListTags, set different each time you callorderParameters or other filtering conditions. For example, the top of the page can displayorder="id desc"The latest article list, which can be displayed beloworder="views desc"The hot article list, which does not affect each other. Just make sure to assign different variable names for eacharchiveListCalling to allocate different variable names, such asarchives_latestandarchives_popular)to do so.

Q2: Why is the article list not displayed as expected on the front end, even though I have set the sorting value in the background?

A2:Please make sure inarchiveListto explicitly use the tag inorder="sort desc"(If you want the larger values to be sorted in front) ororder="sort asc"(If you want the smaller values to be sorted in front). If not specifiedorderThe parameter, the system may use the default sorting method (such as sorting by ID in reverse order), thereby overriding the custom sorting you set in the background.

Q3:archiveListin the labellimitWhat is the relationship between parameters and pagination? How can I implement pagination for the article list?

A3: limitParameters are used to limit the number of articles displayed at one time. If you want to implement pagination, you need toarchiveListput in the tag.typethe parameter totype="page"instead oftype="list". At the same time, inarchiveListlabel'sExternalyou need to usepaginationTag

Related articles

How to filter and display articles in a list or category list based on recommended attributes (such as "Top Story

In content management and website operation, how to effectively highlight key information, guide users to focus on specific articles, is the key to improving website effectiveness.AnQiCMS (AnQiCMS) provides a flexible recommendation attribute feature that allows you to easily filter and display articles in article lists or category lists based on attributes such as "Headline" and "Recommended", thus better realizing content operation strategies.

2025-11-08

How to dynamically display different group Banner slideshows on the website homepage?

The banner carousel on the homepage is an important window to attract visitors' attention and convey core information.By cleverly setting up, we can allow the home page banner slideshow to dynamically display according to different marketing goals or content themes, which can not only improve user experience but also effectively guide users to browse.AnQiCMS (AnQiCMS) offers flexible features to help users easily meet this requirement.Understanding the Banner mechanism of AnQi CMS In AnQi CMS, the management and display of banners have a clear logic

2025-11-08

How to implement the switching display of multilingual website content and adapt to users of different languages?

Today, with the deepening of globalization, a website that supports multilingualism has become a basic requirement for enterprises to expand into international markets and serve global users.AnQiCMS deeply insight into this trend, providing users with a highly efficient and flexible multilingual website content management solution, helping your website easily switch between different language content display and better adapt to users around the world.The core concept of AnQiCMS implementing multi-language website content switching is based on multi-site management.

2025-11-08

How to enable Markdown editor rendering content on the front-end page and display mathematical formulas and flowcharts?

Content operation plays a crucial role in the digital age today.The strength of a Content Management System (CMS) largely depends on its ability to flexibly support a variety of content presentation forms.AnQiCMS (AnQiCMS) leverages its efficient and flexible features to provide a vast space for content creators.Today, we will delve into how to elegantly enable Markdown editor to create content on the Anqi CMS front-end page, and further realize the rendering of mathematical formulas and flowcharts, making your website content more expressive.###

2025-11-08

How to implement content pagination display and customize page navigation style in AnQiCMS template?

As the content of the website becomes richer, how to efficiently display a large amount of information while ensuring a user-friendly browsing experience is an indispensable link in website operation.In AnQiCMS, through the powerful template tag system, we can easily achieve content pagination display and flexibly customize the style of page navigation, making the website content both rich and tidy.--- ### Efficient Content Organization: Implementing Pagination of Content Lists In the AnQiCMS template, the core of implementing content pagination is to use the `archiveList` tag to retrieve document lists

2025-11-08

How to implement a search function on the front end of a website and display a list of search results with highlighted keywords?

When building a rich website, providing an efficient and convenient search function is a key aspect of improving user experience.AnQiCMS (AnQiCMS) has fully considered this from the beginning of its design, through its flexible template engine and built-in tags, we can relatively easily implement search functionality on the website front-end, and further optimize it to make the keywords in the search results stand out and highlight prominently.### Core Mechanism: Understanding the Search Principle of AnQiCMS The core of AnQiCMS website frontend search lies in `search/index.html`

2025-11-08

How to implement filtering in the article list based on custom parameters (such as product features, price range)?

In website operation, we often need to classify and filter content lists more finely to help users quickly find the information they are really interested in.Traditional article classification can solve most problems, but when the content attributes become more complex, such as products with multiple characteristics, price ranges, or events with different themes and participation methods, a single classification seems to be inadequate.

2025-11-08

How to display the link and title of the previous and next article in AnQiCMS template?

It is crucial to provide visitors with a smooth navigation experience in website operation.When a user finishes reading an article, they naturally expect to find more related content, and the "Previous" and "Next" links are the key features to meet this need.They can not only improve the user's stay time on your website, but also have a positive impact on search engine optimization (SEO) by building an internal link structure.AnQiCMS provides concise and efficient built-in tags for template developers, allowing you to easily display links and titles of the previous and next articles on the article detail page.

2025-11-08