How to effectively organize and present an article list 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 system, allowing us to finely filter and sort articles based on category ID and recommendation attributes, thereby achieving precise content placement and optimized display.
Understand the article list tagsarchiveList
The display of AnQiCMS article list depends onarchiveListThis template tag. It is like a universal content query, which can filter out the content we want to display according to various parameters from a massive amount of articles.No matter whether it is the hot recommendation on the homepage or the latest information under a specific category,archiveListCan easily handle.
When in use, we usually assign the query results to a variable, such asarchivesThen proceedforLoop 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 lists,limit="10"The number of displayed articles is limited.
Precise filtering based on category ID
Website content is usually categorized by different themes, and AnQiCMS allows us to filter articles based on these categories. This is done throughcategoryIdParameter to achieve.
specifying a single category: If you only want to display articles under a specific category, just pass the category ID to the
categoryIdparameter. For example, to display articles under the category with ID5‘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 %}Display multiple categories at the same time: If you need to retrieve articles from multiple non-connected categories, you can use English comma
,Connect multiple category IDs:{% 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 in a category page
categoryId,archiveListit will try to automatically read the category ID of the current page and display all articles under it, including articles under its subcategories.- If you want to display only the current category articles 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 wish
archiveListAutomatically read the category ID of the current page and want to display all site articles (or not filter by category on other pages), you can setcategoryId="0".
- If you want to display only the current category articles and not include any subcategories, you can explicitly set
Optimize content exposure by using recommendation attributes
In website operation, we often need to process some special articles with "recommendation", "top" or "slideshow" etc. to increase their exposure. AnQiCMS provides the "recommendation attribute" (flag) To manage these special states.
When editing articles in the background, we can select one or more recommended properties for the article, such as "Headline", "Recommended", "Slideshow", and so on. In the template, throughflagParameters, we can accurately call articles with these attributes.
The recommended attributes supported by AnQiCMS and their corresponding letters are as follows:
- h: Headline article
- c: Recommended article
- f: Slideshow Article
- a: Featured Article
- s: Scrolling Article
- p: Image Article
- j: Jump Article (usually used for external links, but can also be used for internal special markers)
It should be noted that,flagParameters can only be specified once for filtering recommendations. If you want to display specific recommended articles, such as the 'Recommended' articles on the homepage:
{% 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 useexcludeFlagthe parameter. AndshowFlag="true"You can directly display the recommended attributes of the article in the article list (for example, showing a "Recommended" word next to the title).
A flexible sorting mechanism to make the content more orderly.
The presentation order directly affects the efficiency of users in obtaining information. AnQiCMS provides various sorting methods, throughorderparameters to control:
order="id desc": Arranged in descending order by article ID, usually used to display the most recently published articles.descMeans descending,ascMeans ascending.order="views desc": Arrange articles in descending order of views, used to display the most popular or most concerned articles.order="sort desc"This is the default custom sorting method of AnQiCMS admin panel.The operation personnel can manually adjust the priority of articles 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 %}
Apply comprehensively: Build a smarter article list
The strength of AnQiCMS lies in the flexibility of these parameters, which can help us build article lists that meet various needs. For example, we want to be in the "Product Dynamics" category (assuming the ID is10Under, display all "recommended" (cProduct news of the attribute, sorted by views from high to low, limited to display 6 items:
{% 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 a combination of use allows us to dynamically adjust the way content is presented according to the actual operation strategy of the website, whether it is for SEO, users