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 yet powerful way to meet these needs.
One of the core strengths 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, capable of presenting the content of the article in various sorting methods on the website page according to the instructions we provide.
Use flexiblyarchiveListLabel: The conductor of content display
To display the article list, 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,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 instead of a list for pagination.limit="10"It controls the number of articles displayed each time. Most importantly,orderthis parameter determines the sorting rules of the articles.
Set the sorting rules according to different needs.
【en】The AnQi CMS provides several commonly used sorting methods, allowing us to easily handle various content operation scenarios.
【en】1. Latest article sorting: Keep the content fresh.
Website visitors often want to see the latest information.To sort the "latest articles", we can use the article ID or the creation time.In AnQi CMS, article IDs are typically incremental, so sorting by ID in descending order can effectively display the latest published articles.
【en】We just need toarchiveListsetting in the labelorder="id desc",descRepresents descending order, meaning articles with larger (more recent) ID values are shown at the top.
{% 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 users' attention, then sorting by views is the 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 most viewed articles 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 non-time, non-browsing volume factors such as operational activities and thematic recommendations.The AnQi CMS provides the functionality of custom sorting in the backend, allowing us to set a 'sort value' for articles in the article editing interface.
To display the list according to this custom sort value, we can inarchiveListthe label useorder="sort desc"(or}sort ascIt depends on whether you want the sorted value to be large or small in front, usually larger sorted values are placed 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 values we set in the backend.
Combine other filtering conditions to create a more refined list
archiveListThe power of tags also lies in their ability to be combined with other parameters to create more refined article lists. For example:.
categoryId="1":Display articles only under specific categories.flag="c":Only display articles marked as "Recommended" (cis the letter of the recommendation attribute).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 used withorderparameter combinations, for examplecategoryId="1" order="id desc"Displays the latest articles under category ID 1.
Summary
Anqi CMS'sarchiveListTags and their flexible.orderParameters, 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.
Common Questions (FAQ)
Q1: How to display a list of articles with multiple different sorting rules on a single page?
A1:You can use the same page multiple timesarchiveListTags, setting different ones each time you callorderParameters or other filtering conditions. For example, the top of the page can displayorder="id desc"[en]The latest article list, and below can be displayed.order="views desc"[en]The popular article list, which do not affect each other. Just make sure to assign a different variable name for each.archiveList[en]Call allocation different variable names (such as)archives_latestandarchives_popular[en]).
Q2: I have set the article sorting value in the background, but the front-end list is not displaying as expected. Why is that?
A2:Make sure to.archiveListThe tag is explicitly used inorder="sort desc"(If you want the values sorted with the larger ones at the front) ororder="sort asc"(If you want the values sorted with the smaller ones at the front). If not specifiedorderParameters may be sorted in a default manner (e.g., in descending order by ID), overriding any custom sorting you have set up in the background.
Q3:archiveListthe tag inlimitWhat is the relationship between parameters and pagination? How do I implement pagination for article lists?
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 tagtypeparameter settingstype="page",instead oftype="list". Also, inarchiveListTagsexternal,you need to usepaginationtags