How to effectively organize and present article lists in a content management system is a key factor that directly affects user experience and website information architecture.AnQiCMS provides a flexible and powerful template tag set that allows us to finely filter and sort articles based on category ID and recommendation attributes, thus achieving precise content distribution and optimized display.
Understanding article list tagsarchiveList
The display of AnQiCMS article list relies onarchiveListThis template tag.It acts as a versatile content query tool, capable of filtering the content we want to display from a vast amount of articles based on various parameters.archiveListCan handle everything easily.
When in use, we usually assign the query results to a variable, such asarchivesand then throughforLoop through these articles to display them. A basic call might look like this:
{% archiveList archives with type="list" limit="10" %}
{% for item in archives %}
<a href="{{item.Link}}">{{item.Title}}</a>
{# 更多文章详情,如简介、发布时间等 #}
{% endfor %}
{% endarchiveList %}
Heretype="list"Means to get a fixed number of items from a list,limit="10"which limits the number of articles displayed.
Based on category ID filtering
The content of the website is usually categorized by different themes, and AnQiCMS allows us to filter articles based on these categories. This is achieved bycategoryIdparameters.
Specify a single category If you only want to display articles under a specific category, just pass the ID of that category to the
categoryIdparameter. For example, to display articles with ID5The articles under the "Company News" category:{% archiveList articlesByCategory with categoryId="5" limit="5" %} {% for article in articlesByCategory %} <h3><a href="{{article.Link}}">{{article.Title}}</a></h3> <p>{{article.Description}}</p> {% endfor %} {% endarchiveList %}Show multiple categories at the same timeIf you need to retrieve articles from multiple non-connected categories, you can use English commas
,Join multiple category IDs together:{% archiveList mixedArticles with categoryId="1,3,7" limit="10" %} {% for article in mixedArticles %} <h4><a href="{{article.Link}}">{{article.Title}}</a></h4> {% endfor %} {% endarchiveList %}Include or exclude subcategoriesBy default, if you do not specify anything on a category page:
categoryId,archiveListThe system will attempt to automatically read the current page's category ID and display all articles under it, including the articles under its subcategories.- If you want to display only the articles of the current category and not include any subcategories, you can explicitly set
child="false":{% archiveList currentCategoryArticles with child="false" limit="8" %} {# 仅显示当前分类下的文章 #} {% endarchiveList %} - If you need to exclude certain categories of articles, you can use
excludeCategoryIdParameters:{% archiveList allButExcluded with excludeCategoryId="2,4" limit="10" %} {# 显示除分类ID 2和4之外的所有文章 #} {% endarchiveList %} - If you do not want
archiveListAutomatically read the category ID of the current page and want to display all the articles on the site (or not filtered by category on other pages), you can setcategoryId="0".
- If you want to display only the articles of the current category and not include any subcategories, you can explicitly set
Optimize content exposure using recommendation attributes
In website operation, we often need to process some special articles with "recommendflag)to manage these special states.
When editing articles in the background, we can select one or more recommended properties for the article, such as "Top News", "Recommendation", "Slider", etc. In the template, throughflagParameters, we can accurately call articles with these properties.
The recommended attributes supported by AnQiCMS and their corresponding letters are as follows:
- h: Headline article
- c: Recommended article
- f:Slide Article
- a:Featured Article
- s:Rolling Article
- p:Image Article
- j:Jump Article (usually used for external links, but can also be used as internal special markers)
It is worth noting that,flagThe parameter can only specify one recommended attribute for filtering at a time. If you want to display specific recommended articles, such as the 'Recommended' articles on the homepage of the website:
{% archiveList recommendedArticles with flag="c" limit="4" %}
{% for article in recommendedArticles %}
<div class="card">
<h4><a href="{{article.Link}}">{{article.Title}}</a></h4>
<p>{{article.Description|truncatechars:100}}</p>
</div>
{% endfor %}
{% endarchiveList %}
Similarly, if you want to exclude articles with certain recommended properties, you can useexcludeFlagparameters.showFlag="true"Then the recommended attributes of the article (such as displaying a "recommended" word next to the title) can be directly displayed in the article list.
Flexible sorting mechanism, making the content more orderly
The presentation order of content directly affects the efficiency of users in obtaining information. AnQiCMS provides multiple sorting methods, throughorderparameters to control:
order="id desc": Arrange articles in reverse order by article ID, usually used to display the latest published articles.descMeans descending order,ascMeans ascending order.order="views desc"English: According to the article view count in descending order, used to display the most popular or most concerned articles.order="sort desc"This is the default custom sorting method of AnQiCMS backend.The operator can manually adjust the priority of the article in the background. The higher the number, the higher the sorting.If you want the articles to be displayed in the order set by the background, this parameter is very useful.
For example, to display the latest 5 articles:
{% archiveList latestArticles with order="id desc" limit="5" %}
{% for article in latestArticles %}
<li><a href="{{article.Link}}">{{article.Title}}</a> (发布时间: {{stampToDate(article.CreatedTime, "2006-01-02")}})</li>
{% endfor %}
{% endarchiveList %}
Display the top 3 most popular articles:
{% archiveList hotArticles with order="views desc" limit="3" %}
{% for article in hotArticles %}
<p><a href="{{article.Link}}">{{article.Title}}</a> (浏览量: {{article.Views}})</p>
{% endfor %}
{% endarchiveList %}
Comprehensive Application: Build a smarter article list
The strength of AnQiCMS lies in the flexibility of these parameters, which help us build article lists that meet various needs. For example, if we want to display articles in the "Product Dynamics" category (assuming ID is10)下,显示所有“Recommended”(c属性)的产品新闻,并且按照浏览量从高到低排序,限制显示6条:
{% archiveList productNews with categoryId="10" flag="c" order="views desc" limit="6" %}
{% for item in productNews %}
<div class="news-item">
<h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
<p>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}} | 浏览:{{item.Views}}</p>
<p>{{item.Description|truncatechars:120}}</p>
</div>
{% else %}
<p>当前分类下没有推荐的产品动态。</p>
{% endfor %}
{% endarchiveList %}
such combinations allow us to dynamically adjust the way content is presented based on the actual operational strategy of the website, whether it is for SEO, users