As an experienced AnQiCMS (AnQiCMS) website operations manager, I fully understand the importance of content presentation for website user experience and content marketing effectiveness.AnQi CMS provides a powerful and flexible template tag system, which allows us to easily obtain and display various types of articles and product lists, whether it is the latest content update or a special theme display under a specific category, all can be achieved through simple configuration.
Understanding the content model of Anqi CMS
Before starting to retrieve the content list, understanding the content model of Anqi CMS is fundamental.The AnQi CMS supports custom content models, but the default usually includes the 'Article Model' and the 'Product Model'.moduleIdFor example, the article model usually corresponds tomoduleIdIt could be1, the product model could be2. When calling the content list in our template, specify the correctmoduleIdIt is crucial, it ensures that we get the expected type of content.
Get the latest released or updated articles/products list
Displaying the latest updates on the website is an effective way to attract users and enhance activity. In Anqi CMS, to obtain the latest published articles or product lists, it mainly relies onarchiveListTemplate tag. This tag provides rich parameters for filtering, sorting, and limiting the display of content.
To obtain the latest content, we usually use the content ID for reverse sorting, as the ID is usually incremented, representing the order of content publication. By settingorder="id desc"The system will sort the content by content ID in descending order, that is, the latest released content will be at the top. At the same time,limitThe parameter can control how many items you want to display.
For example, to display the latest 5 news articles (assuming the article modelmoduleIdWith1), you can write the template code like this:
{# 获取最新发布的5篇新闻文章 #}
{% archiveList latestNews with moduleId="1" order="id desc" limit="5" %}
{% for item in latestNews %}
<div class="news-item">
<h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
<p>{{ item.Description|truncatechars:100 }}</p> {# 截取描述前100个字符 #}
<span class="publish-date">发布日期: {{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span>
</div>
{% endfor %}
{% endarchiveList %}
In this code block,latestNewsis the custom variable name you use to store the list of content queried.moduleId="1"We clarified that we need to obtain the article.order="id desc"We ensured that the content is sorted by the latest release.limit="5"It limited the display to only 5 items.stampToDateThe tags help us format the timestamp into a readable date.
Get the list of articles/products under a specified category
Create a content list for a specific topic or product series, which is the key to building a clear website structure and guiding user browsing.archiveListThe label can also perform this task exceptionally well, its core lies incategoryIdParameter.
You can use it tocategoryIdSpecify an ID for one or more categories to get the content under them. If multiple category IDs are specified, they must be separated by commas. By default,archiveListIt will include the content of the specified category and all its subcategories. If you only want to get the content of the current category (excluding its subcategories), you can set it additionallychild="false".
For example, to display “Product Category A” (assuming itscategoryIdWith10all products under it (assuming the product model ismoduleIdWith2), you can write it like this:
{# 获取“产品分类A”下最新的8个产品 #}
{% archiveList categoryProducts with moduleId="2" categoryId="10" order="id desc" limit="8" %}
{% for item in categoryProducts %}
<div class="product-card">
<a href="{{ item.Link }}">
<img src="{{ item.Thumb }}" alt="{{ item.Title }}">
<h3>{{ item.Title }}</h3>
<p class="price">¥ {{ item.Price }}</p>
</a>
</div>
{% endfor %}
{% endarchiveList %}
If you want to get the “Solution” (categoryIdWith12)and "Industry Cases"(categoryIdWith15)articles under these two categories, and only include the content of these two categories themselves, not the subcategories, the code will be like this:
{# 获取“解决方案”和“行业案例”分类下,不含子分类的文章 #}
{% archiveList caseStudies with moduleId="1" categoryId="12,15" child="false" limit="10" %}
{% for item in caseStudies %}
<div class="study-item">
<h4><a href="{{ item.Link }}">{{ item.Title }}</a></h4>
<p>{{ item.Description|truncatechars:150 }}</p>
</div>
{% endfor %}
{% endarchiveList %}
Display a large amount of content combined with pagination
When there is a large amount of content under a category, in order to avoid the page being too long and slow to load, we usually display it with pagination.archiveListTag by settingtype="page"Parameters, can automatically handle pagination logic. After that, you can usepaginationTag to render pagination navigation links.
”`twig {# Fetch all articles under the “Blog” category, display 10 per page, and enable pagination #} {% archiveList blogPosts with moduleId=“1” categoryId=“20” type=“page” limit=“10” %}
{% for item in blogPosts %}
<article class="blog-post">
<h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2>
<p class="post-meta">发布于 {{ stampToDate(item.CreatedTime, "2006-01-02") }}</p>
<div class="post-summary">{{ item.Description|safe }}</div>
<a href="{{ item