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