Mastering Precision: A Practical Guide to Controlling the Number and Sorting of Articles on the CMS Article List Page
In content operation, the article list page of the website is an important window for users to browse content and discover information.A layout that is well-organized and content-wise, which not only enhances user experience but is also a key element of Search Engine Optimization (SEO).The AQ CMS is proficient in this, allowing you to easily and precisely control the number of articles displayed on each page and the sorting method of the content through its powerful and flexible template tag system.
This article will guide you to delve deeper into how to achieve this goal by using core template tags in the AnQi CMS, making your website content more attractive and logical.
Core Tag Unveiling:archiveListPowerful Features
In the Aqii CMS, the call of all article, product and other content data depends on a core tag:archiveList.It is like your dedicated content manager, capable of accurately filtering and presenting the required articles from a vast content library according to your instructions.The core that controls the display quantity and sorting method per page, and it is also realized through different parameters of this tag.
Number of Controls:limitParameters and Flexible Pagination
To control how many articles are displayed per page on the list page,archiveListthe tag'slimitthe parameter is your preferred tool.
If your list page does not need pagination and you just want to display a fixed number of articles, such as the "Latest Articles" module on the homepage, you can set the parameter totypetolistand cooperate withlimitSpecify the number of items to display. For example, to display only the latest 5 articles:
{% archiveList archives with type="list" limit="5" %}
{% for item in archives %}
<li><a href="{{item.Link}}">{{item.Title}}</a></li>
{% endfor %}
{% endarchiveList %}
For articles list pages that require pagination, such as all articles under a category, you need to:typetopageAt this point,limitThe parameter's role has become to define the "number of articles per page". To enable full page number navigation on the page, we also need to introducepaginationLabel:
{% archiveList archives with type="page" limit="10" %} {# 每页显示10篇文章 #}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
<p>{{item.Description}}</p>
<span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
<span>浏览量:{{item.Views}}</span>
</a>
</li>
{% endfor %}
{% endarchiveList %}
{# 分页导航 #}
<div class="pagination">
{% pagination pages with show="5" %} {# 最多显示5个页码按钮 #}
<ul>
<li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
{% if pages.PrevPage %}
<li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
{% endif %}
{% for item in pages.Pages %}
<li class="{% if item.IsCurrent %}active{% endif %}"><a href="{{item.Link}}">{{item.Name}}</a></li>
{% endfor %}
{% if pages.NextPage %}
<li><a href="{{pages.NextPage.Link}}">下一页</a></li>
{% endif %}
<li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
</ul>
{% endpagination %}
</div>
In this code block,archiveListbylimit="10"Tell the system to display 10 articles per page, andpaginationThe label is responsible for generating navigation links such as "Homeshow="5"The parameter controls the maximum number of middle page buttons displayed.
Define order:orderMultiple parameter options
The sorting method of the article directly affects the presentation logic of the content and the reading habits of users. The Anqi CMSarchiveListTags provide flexibleorderParameters, allowing you to sort articles according to different logic based on actual needs.
Common sorting methods include:
- Latest release:It is usually the default sorting method of the website, articles are sorted by
id descDisplay in reverse order by ID, that is, in reverse order of publication time. The latest articles are at the top. - Hot articles:Based on the number of page views of the articles
viewsSort. For example,order="views desc"The article with the highest view count will be displayed first. - Custom sorting in the background:If you wish to manually adjust the order of articles, you can set a "display order" value when editing articles in the background, and then use
order="sort desc"Call it. The smaller the number, the earlier it is usually (specifically depending on the backend settings). - Mixed sorting:You can also combine multiple sorting rules, for example
order="flag desc|views desc"It will first sort by recommended attributes (flag), and then sort by views in case of the same recommended attributes.
The following is an example of an article list sorted by views from high to low:
{% archiveList hotArchives with type="list" limit="8" order="views desc" %} {# 获取浏览量最高的8篇文章 #}
<h3>热门文章</h3>
<ul>
{% for item in hotArchives %}
<li><a href="{{item.Link}}">{{item.Title}} - {{item.Views}}次浏览</a></li>
{% endfor %}
</ul>
{% endarchiveList %}
Integrate application: Make content display more accurate
BesideslimitandorderParameters,archiveListTags support multiple filtering conditions, allowing you to control the displayed content on the list page more accurately:
categoryId:Specify the category ID to which the article belongs. For example:categoryId="1"Only display articles under the category with ID 1.moduleId:Specify the model ID of the article. For examplemoduleId="1"Only show the content under the “Article Model”, whilemoduleId="2"it will show the content under the “Product Model”.flag:Filter based on the recommended attributes of the article (such as "头条[h]", "推荐[c]", etc.). For exampleflag="h"Only show articles marked as headlines.q:On the search results page,qThe parameter can match content in the article title that includes specific keywords.
By flexibly combining these parameters, you can create various complex and logically structured article list pages, whether it is by category, tag, or combined with popular, recommended properties, all can be realized in Anqi CMS.
Practice Case: Step-by-step Configuration of List Page
- Confirm Template File:First, find the template file corresponding to the list page you want to modify. The naming convention of the template for the article category list page may be
{模型table}/list.htmlor{模型table}/list-{分类ID}.html. - Write
archiveListLabel:In the template,archiveListTag to get article data and set it according to requirementstypeTopageandlimitParameters to define the number of items per page