AnQiCMS Content Model Deep Guide: How to usearchiveListPrecisely filter document list
As a veteran in website operations for many years, I deeply understand the importance of a flexible and efficient content management system for a corporate website.AnQiCMS with its efficient architecture based on the Go language and highly customizable features, provides us with strong support in the content management field.Content modelThe feature is undoubtedly one of the highlights of AnQiCMS, allowing us to create and manage different types of content structures according to business needs, such as articles, products, cases, news, events, and so on.
Today, let's delve deeply into a very commonly used and powerful template tag in AnQiCMS -archiveListand focus on how to combinemoduleIdParameter, realize accurate filtering and display of document lists for specific content models.This can not only make your website content organized, but also provide users with a clearer and more targeted browsing experience.
Flexible content model: the cornerstone of refined management
In AnQiCMS, the content model is the core that defines the content type and its field structure.The system is built-in with "Article Model" and "Product Model", but the real power lies in being able to create an infinite number of custom models according to your actual business needs.For example, if you run a real estate website, you can create a 'listing model'; if it is a food blog, then you can create a 'recipe model'.moduleId.
ThismoduleIdIt is like the 'ID number' of the content world. When you publish an 'article', it is endowed with the article model'smoduleId; When releasing a 'product', it also has a product model.moduleId. It is this small onemoduleId, allowing us to accurately retrieve the information we want from the ocean-like content.
archiveListLabel: core driving of content display
archiveListIt is one of the most commonly used tags in the AnQiCMS template, responsible for retrieving and displaying a list of documents (i.e., all the content we create). Whether it's the latest dynamic on the homepage, the popular recommendations in the sidebar, or the detailed list on the category page, archiveListThey all play a crucial role.
Its basic usage is to iterate over the content, and extract the attributes of each content for display. To make this label 'smart', it can identify and filter content of different models.moduleIdParameters are particularly important.
Hand in handmoduleId: Filter your content list accurately.
When we need to display documents under a specific content model on a page or in a certain area of a website,moduleIdthe parameter is our first choice. By using inarchiveListExplicitly specify in the tagmoduleIdThe system can accurately filter out the document list belonging to the content model.
For example, suppose your "article model" ismoduleIdIs1while the "product model" ismoduleIdIs2You need to use two separate ones to display the latest article list in one area of the homepage and the recommended product list in another area.archiveListLabel, and throughmoduleIdto differentiate.
{# 获取文章模型的文档列表,假设文章模型的 moduleId 为 1 #}
{% archiveList latestArticles with moduleId="1" type="list" limit="5" order="id desc" %}
{% for item in latestArticles %}
<div class="news-item">
<a href="{{ item.Link }}">
<h4>{{ item.Title }}</h4>
<p>{{ item.Description|truncatechars:100 }}</p> {# 截取描述,保持简洁 #}
<span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</a>
</div>
{% empty %}
<p>暂无最新文章。</p>
{% endfor %}
{% endarchiveList %}
{# 获取产品模型的文档列表,假设产品模型的 moduleId 为 2 #}
{% archiveList featuredProducts with moduleId="2" type="list" limit="3" order="views desc" %}
{% for item in featuredProducts %}
<div class="product-card">
<a href="{{ item.Link }}">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}">
{% endif %}
<h5>{{ item.Title }}</h5>
<p>浏览量:{{ item.Views }}</p>
</a>
</div>
{% empty %}
<p>暂无推荐产品。</p>
{% endfor %}
{% endarchiveList %}
In the above example, we clearly sawmoduleId="1"andmoduleId="2"how twoarchiveListlabels were pulled apart, so that they are only responsible for displaying the documents under their respective content models.
exceptmoduleIdYou can also combine other parameters to further optimize your content list:
type: List typetype="list"Used to get a fixed number of lists, for example, the "Latest Articles" block on the homepage, which only displays the first 5.type="page": Used for paginated lists, such as article list pages or product display pages, in conjunction withpaginationlabel usage
limit: Show the number- Control the number of documents returned in the list, such as
limit="10"Means to retrieve 10 documents.
- Control the number of documents returned in the list, such as
order: Sorting methodorder="id desc": Sort by document ID in reverse, usually used to display the latest released documents.order="views desc": Sort by views in reverse, suitable for hot rankings and others.order="sort desc"Custom sorting on the backend is provided, offering operational flexibility.
categoryIdCategory ID- Under a specific model, you can further proceed through.
categoryIdFilter documents that belong to a certain category. For example,moduleId="1" categoryId="10"Only get the articles under the "Article Model" and with category ID 10.
- Under a specific model, you can further proceed through.
Practice exercise: Build a list of multi-model content.
Let us go through a more complete example to show how to use in the AnQiCMS template,archiveListandmoduleIdParameter, elegantly displaying a list of documents for different content models.Assuming we have a homepage for a website that needs to display the 'Latest News' and 'Featured Services' sections.moduleId=1), the special service belongs to the 'Service Model'(moduleId=3This is a custom model)
`twig
{# 最新新闻区 - 假设新闻对应文章模型 moduleId 为 1 #}
<section class="latest-news">
<h2>最新新闻</h2>
<div class="news-list">
{% archiveList newsItems with moduleId="1" type="list" limit="4" order="id desc" %}
{% for item in newsItems %}
<article class="news-card">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="news-thumbnail">
{% endif %}
<div class="news-content">
<h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
<p>{{ item.Description|truncatechars:120 }}</p>
<time datetime="{{ stampToDate(item.CreatedTime, "2006-01-02T15:04:05") }}">
{{ stampToDate(item.CreatedTime, "2006年01月02日") }}
</time>
<span class="news-views">浏览:{{ item.Views }}</span>
</div>
</article>
{% empty %}
<p>目前还没有新闻发布,敬请期待!</p>
{% endfor %}
{% endarchiveList %}
</div>
</section>
<hr>
{# 特色服务区 - 假设服务模型 moduleId 为 3 #}