How to accurately retrieve related documents based on `tagId` from the `tagDataList` tag?

As a senior website operation expert, I have a deep understanding of AnQiCMS's powerful content management capabilities.In daily operations, the refined organization and efficient distribution of content are the key to improving user experience and SEO performance.tagDataList, see how it helps us according totagIdAccurately retrieve relevant documents to better construct the content ecosystem.

Flexible content aggregation: UnderstandtagDataListCore value

In AnQiCMS, tags (Tag) are one of the important dimensions for organizing content, which is more flexible and has horizontal relevance compared to traditional categories (Category).When a user enters an aggregation page through a tag, or when we want to recommend related tags at the bottom of an article, we need a mechanism to accurately retrieve all documents associated with that tag.tagDataListLabels are 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 user discovery paths.

Precise localization:tagIdThe magic of

tagDataListThe core of a tag lies in itstagId参数。Each label created in the AnQiCMS backend will have a unique digital ID.tagIdjust like the 'ID card number' of content,tagDataListCan accurately find all documents marked with this specific tag, just like a navigator.

to usetagDataListThe most basic syntax structure is:

{% tagDataList archives with tagId="1" %}
    {# 在这里循环输出与tagId为1的标签关联的文档 #}
{% endtagDataList %}

In this example,archivesIt is a variable name we customize, which will carry all the document data obtained.tagId="1"It explicitly 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 tag detail page (for example/tag/某个标签别名), thentagDataListthe tag will be very intelligent. In this case, even if you do not explicitly specifytagIdIt will also attempt to automatically read the current page's tag ID and automatically display all documents related to the current tag, thus saving the trouble of manually obtaining the ID.

Beyond the Basics: UncovertagDataListThe more advanced features

In addition to the basictagIdLocation,tagDataListAlso provides a series of parameters to make content acquisition and display more flexible and powerful:

  • moduleIdLimit the content modelIn 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 for a particular model (such as displaying articles but not products), you can usemoduleIdparameters. For example,moduleId="1"English for: Typically used to obtain documents under the article model.

  • order:Control sorting methodThe order in which documents are displayed is crucial for user experience.tagDataListSupports various sorting rules, such as:

    • order="id desc":By document ID in reverse order, usually meaning the most recently released documents are at the top.
    • *order="views desc":By view count in reverse order, popular documents are displayed first.
    • order="sort desc":Based on the custom sorting set in the background display.
  • limitWithtype="page":Implement elegant pagination.When there are many documents under a tag, loading all at once will affect page performance and user experience.tagDataListCombinelimitandtype="page"Parameters can easily implement pagination.limitDefine the number of documents displayed per page,type="page"which indicates that it is a pagination list and needs to be used with the AnQiCMS pagination tagspaginationUse. You can also uselimit="2,10"in the form, starting from the second item, get 10 data items to achieve finer offset control.

  • siteId: Content sharing across multiple sitesFor 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

PasstagDataListEach document obtained (inforusually represented byitem), all contain rich properties that can be used to display on the front-end page:

  • item.Id: Document ID
  • item.Title: Document Title
  • item.Link:Document detail page link
  • item.Description:Document introduction
  • item.Thumboritem.Logo:Document thumbnail or cover image
  • item.Views:Document Views
  • item.CreatedTime:Document creation time (timestamp, needs to bestampToDateformatted)
  • item.CategoryId:Document category ID (can be used with)categoryDetailtags to get category information)

When displaying dates, please make sure to use{{stampToDate(item.CreatedTime, "2006-01-02")}}such formatting functions to convert timestamps into readable date formats.

English Practice: A Comprehensive Example

The details page of the label "Go language" is being built, and it is expected to display all articles under this label with pagination, including the title, introduction, category, publish time, view count, and thumbnail.

`twig {# Firstly, use tagDetail to get the current tag's title and description 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 %}">
            <