As an experienced website operation expert, I have a deep understanding of the powerful content management capabilities of AnQiCMS (AnQiCMS).In daily operation, the fine organization and efficient distribution of content are the key to improving user experience and SEO performance.Today, we will delve into a very practical template tag in AnQiCMS—tagDataListLet's see how it helps us based ontagIdAccurately obtain relevant documents to better build a content ecosystem.
Flexible content aggregation: understandingtagDataListThe core value
In AnQiCMS, tags (Tag) are one of the important dimensions for organizing content, and they are more flexible and horizontally correlated than traditional categories (Category).When a user enters an aggregated page through a tag, or we want to recommend related tag content at the bottom of the article, we need a mechanism to accurately retrieve all documents associated with that tag.tagDataListThe tag is born for this. It allows us to display related documents scattered across various categories and models based on a specific tag ID, greatly enriching the internal links of the website content and the user discovery path.
Accurate positioning:tagIdMagic
tagDataListThe core of tags lies in itstagIdParameters. Each tag created in the AnQiCMS backend will have a unique numeric ID. ThistagIdis like the 'ID card' of the content, through which,tagDataListCan find all documents tagged with this specific label accurately, like a navigator.
To usetagDataListThe basic syntax structure is:
{% tagDataList archives with tagId="1" %}
{# 在这里循环输出与tagId为1的标签关联的文档 #}
{% endtagDataList %}
In this example,archivesIt is a custom variable name that will carry all the document data obtained.tagId="1"It clearly tells the system that we want to retrieve all documents associated with the tag ID 1.
It is worth mentioning that if you are developing a label detail page (such as/tag/某个标签别名ThentagDataListthe label will be very intelligent. In this case, even if you do not explicitly specifytagIdIt also tries to automatically read the current page's tag ID, thus automatically displaying all documents related to the current tag, saving the trouble of manually obtaining the ID.
Beyond the Basics: ExploretagDataListMore advanced features
In addition to the basictagIdLocation,tagDataListAnd provides a series of parameters to make content acquisition and display more flexible and powerful:
moduleId: Content model restrictionIn AnQiCMS, content can belong to different models, such as article models, product models, etc. If you only want to retrieve documents under a specific tag of a particular model (for example, only displaying articles and not displaying products), you can usemoduleIdthe parameters. For example,moduleId="1"Used to retrieve documents under the article model.order: Controls sorting methodThe display order of documents is crucial for user experience.tagDataListSupports various sorting rules, such as:order="id desc": The documents are sorted by document ID in descending order, usually meaning the most recently published documents are listed first.- *
order="views desc": The documents are sorted by view count in descending order, with popular documents displayed first. order="sort desc": Displayed according to the custom sorting set in the background.
limitwithtype="page": Implement elegant paginationWhen there are many documents under a tag, loading them all at once will affect page performance and user experience.tagDataListCombinelimitandtype="page"Parameters can easily implement pagination.limitDefine the number of documents to display per page, andtype="page"then indicates that this is a pagination list, which needs to be used in conjunction with the AnQiCMS pagination tagspaginationUse. You can also uselimit="2,10"in the form, starting from the second item, get 10 data to achieve more fine-grained offset control.siteId: Multi-site content sharingFor users who have deployed multiple AnQiCMS sites,siteIdThe parameter allows you to call documents under specified tags across sites, which is very useful when building a content matrix for multiple sites.
Get document details: rich content display
BytagDataListEach document obtained (inforusually represented byitem
item.Id:Document IDitem.Title:Document titleitem.Link: Document detail page linkitem.Description: Document introductionitem.Thumboritem.Logo: Document thumbnail or cover imageitem.Views: Document viewsitem.CreatedTime: Document creation time (timestamp, needs to be paired withstampToDateFormatitem.CategoryId: Document category ID (can be used withcategoryDetailtags to get category information
Be sure to use when displaying the date{{stampToDate(item.CreatedTime, "2006-01-02")}}This formatting function converts timestamps into a readable date format.
Practical exercise: A comprehensive example.
Assuming we are building a detail page for the label "Go Language", hoping to display all the articles under the label, and implement pagination, while displaying the title, summary, category, publication time, view count, and thumbnail of the articles.
”`twig {# Firstly, use tagDetail to get the title and description of the current tag for use in page TDK or title display #} {% tagDetail currentTag with name=“Title” %} {% tagDetail tagDescription with name=“Description” %}
Label: {{ currentTag }}
{{ tagDescription }}
{# 使用tagDataList获取当前标签下的文档列表,并按浏览量降序,每页显示10条,开启分页功能 #}
{% tagDataList archives with type="page" order="views desc" limit="10" %}
{% for item in archives %}
<article class="document-item">
<a href="{{ item.Link }}" title="{{ item.Title }}">
{% if item.Thumb %}
<div class="document-thumbnail">
<img src="{{ item.Thumb }}" alt="{{ item.Title }}">
</div>
{% endif %}
<div class="document-content">
<h2>{{ item.Title }}</h2>
<p class="document-description">{{ item.Description }}</p>
<div class="document-meta">
{# 获取文档所属分类的标题和链接 #}
<span>分类:
{% categoryDetail docCategory with name="Title" id=item.CategoryId %}
{% categoryDetail docCategoryLink with name="Link" id=item.CategoryId %}
<a href="{{ docCategoryLink }}">{{ docCategory }}</a>
</span>
{# 格式化文档发布时间 #}
<span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
<span>浏览量:{{ item.Views }}</span>
</div>
</div>
</a>
</article>
{% empty %}
<p>该标签下暂无相关文档。</p>
{% endfor %}
{% endtagDataList %}
{# 分页导航区域,配合tagDataList的type="page"使用 #}
<div class="pagination-area">
{% pagination pages with show="5" %}
<ul class="pagination-list">
{# 首页链接 #}
<li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
<a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
</li>
{# 上一页链接 #}
{% if pages.PrevPage %}
<li class="page-item">
<a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>
</li>
{% endif %}
{# 中间页码链接 #}
{% for pageItem in pages.Pages %}
<li class="page-item {% if pageItem.IsCurrent %}active{% endif %}">
<a href="{{pageItem.Link}}">{{pageItem.Name}}</a>
</li>
{% endfor %}
{# 下一页链接 #}
{% if pages.NextPage %}
<li class="page-item">
<a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>
</li>
{% endif %}
{# 末页链接 #}
<li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
<