How to get the associated document list based on Tag ID and how to paginate it for `tagDataList` tags?

Calendar 👁️ 76

In website content operation, effectively organizing and displaying related content is crucial for improving user experience and the SEO performance of the website. AnQiCMS (AnQiCMS) provides powerful tag functions, among whichtagDataListTags are the key tools to help us achieve this goal.It can flexibly retrieve all associated document lists based on the specified tag ID, and easily achieve content pagination display through cooperation with other tags.

UnderstandingtagDataListLabel: Bridge of content association

tagDataListThe core function of the tag is to retrieve the documents associated with the tag.Imagine you have a website with many blog posts about 'SEO tips', and you link them together with the tag 'SEO tips'.Now, you hope to display a list of articles with the tag "SEO Tips" on a page of your website, such as the tag detail page of "SEO Tips", or in the sidebar of other articles.at this time,tagDataListit comes in handy.

This label provides several important parameters for fine-grained control of content retrieval:

  • tagIdThis is the most critical parameter, you need to provide a tag ID. If you are currently on a tag detail page and have not specified it explicitlytagIdthentagDataListIt will intelligently automatically read the tag ID of the current page. Of course, you can also manually specify any tag ID, such astagId="10".
  • moduleIdIf your website uses a different content model (such as articles, products), you can use this parameter to limit the documents to be retrieved from a specific model. For example,moduleId="1"It may represent only retrieving documents under the "Article" model.
  • order: The sorting method of the document. You can choose to sort in reverse order by publication time (order="id desc")、in reverse order by views(order="views desc"), or by custom sorting set by the backend (order="sort desc") and so on.
  • limit: Controls the number of documents displayed. If you just want to display the first few contents, you can setlimit="5". It also supportsoffsetpatterns, such aslimit="2,10"It means to get 10 data items starting from the 2nd one.
  • type: This parameter is very critical. When you need to implement pagination, you must set it totype="page". If you just want to list a fixed number of documents, you can use the default valuelist.
  • siteIdIf you have enabled the multi-site management feature and want to call data from other sites, you can specify the site ID through this parameter.

tagDataListThe tag will return an array of document objects, usually we would usefora loop to traverse and display each document.

Combinepaginationthe tag to implement elegant pagination

WhentagDataListoftypethe parameter is set to"page"It will cooperate when,paginationLabels work together to jointly implement pagination display on the page.paginationLabels are responsible for generating page navigation, allowing users to easily switch between different pages.

paginationTags provide ashowThe parameter is used to control the maximum number of page number buttons displayed in the page navigation bar, for exampleshow="5"It will display up to 5 page numbers before and after the current page.

It will return apagesAn object that contains all the information needed for pagination: total number of items (TotalItems)、total number of pages(TotalPages)、current page(CurrentPage) as well as the links and names of the first page (FirstPage) and the last page (LastPage)、previous page(PrevPage),next page(NextPage) The most important thing is that it also provides aPagesAn array that contains all the detailed information of the middle page numbers, convenient for us to loop render page number links.

Actual operation: Get the label document and display it in pages.

Now, let's look at a specific example of how to combinetagDataListandpaginationTo implement displaying all documents under a tag on a tag detail page with pagination.

Suppose we are editing a namedtag/list.htmlThe template, this is the default tag document list page template of Anqi CMS.

{# 首先,使用tagDataList标签获取指定Tag关联的文档列表 #}
{# 注意:将type参数设置为"page"以启用分页功能 #}
{% tagDataList archives with type="page" limit="10" %} {# 每页显示10篇文档 #}

    {% if archives %}
    <div class="tag-document-list">
        {% for item in archives %}
        <div class="document-item">
            <a href="{{item.Link}}">
                {# 显示文档标题 #}
                <h3>{{item.Title}}</h3>
                {% if item.Thumb %}
                {# 如果文档有缩略图,则显示 #}
                <img src="{{item.Thumb}}" alt="{{item.Title}}">
                {% endif %}
                {# 显示文档简介 #}
                <p>{{item.Description}}</p>
                <div class="document-meta">
                    {# 显示文档所属分类 #}
                    <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
                    {# 格式化显示发布时间 #}
                    <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                    {# 显示浏览量 #}
                    <span>浏览量:{{item.Views}}</span>
                </div>
            </a>
        </div>
        {% endfor %}
    </div>
    {% else %}
    <p>该标签下暂无任何文档。</p>
    {% endif %}

{% endtagDataList %}

{# 接下来,使用pagination标签生成分页导航 #}
<div class="pagination-container">
    {% pagination pages with show="5" %} {# 最多显示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 item in pages.Pages %}
        <li class="page-item {% if item.IsCurrent %}active{% endif %}">
            <a href="{{item.Link}}">{{item.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 %}">
            <a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
        </li>
    </ul>
    <p class="pagination-info">
        总共有 {{pages.TotalItems}} 篇文档,分为 {{pages.TotalPages}} 页,当前是第 {{pages.CurrentPage}} 页。
    </p>
    {% endpagination %}
</div>

In this code block,tagDataListResponsible for querying and providing document data,paginationBased ontagDataListThe query results, automatically generated the complete page navigation. Throughfor item in archivesWe have sequentially displayed the core information of each document, such as the title, introduction, classification, publication time, and page views, and have usedif item.Thumbto determine if there is a thumbnail. The pagination part is traversedpages.PagesAn array dynamically generates page link and provides navigation to the first page, previous page, next page, and last page.

Practical skills to improve content operation efficiency

Rational utilizationtagDataListAnd the pagination feature can bring many benefits to the website:

  • optimize user experienceUsers can quickly find related content based on their interests, and pagination avoids the fatigue caused by too long content on a single page.
  • Enhance website navigation: Tabs are inherently an effective form of categorization navigation, combined with pagination, they can better organize a large amount of content.
  • Improve SEO effectiveness: A clear tab structure and a friendly URL (configured through pseudo-static rules) helps search engines better crawl and index website content, improving the ranking of relevant keywords.

By using these tags flexibly, AnQi CMS can help you build a content-rich, well-structured, and user-friendly website, thereby more effectively managing content operations.


Frequently Asked Questions (FAQ)

How to get the Tag ID of the current Tag page?

Intag/list.htmlIn such a tag detail template,tagDataListTag without specifyingtagIdWhen a parameter is specified, it will intelligently automatically read the corresponding tag ID from the current page URL. Therefore, you usually do not need to manually obtain and pass it in.tagIdJust use it directly.{% tagDataList archives with type="page" limit="10" %}You can do it. If you really need to get it, you can do it through{% tagDetail with name="Id" %}Tag to directly get the Tag ID of the current page.

2. How can I display the Tag document of a specific model (such as the "Product" model)?

You can intagDataListthe tag withmoduleIdSpecify the model. For example, if the ID of the “Product” model is2, you can use the label in this way:{% tagDataList archives with type="page" limit="10" moduleId="2" %}Thus,tagDataListOnly queries and displays documents associated with the label and belonging to the 'product' model.

3. Why doesn't my pagination show up?

usually, pagination does not display for several common reasons:

  • typethe parameter is not set to"page":tagDataListmust be specifiedtype="page",paginationlabel to obtain complete pagination data.
  • limitincorrectly setIf:limitSet too large, for examplelimit="9999"There will be no pagination if all documents are displayed on one page. Make surelimitSet reasonable, less than the total number of documents.
  • Not enough documents to trigger paginationIf the number of documents associated with this tag is less than or equal to the one you setlimitThe system will not generate pagination navigation if the quantity is set. For example, if you set 10 articles per page, but there are only 8 documents under the tag, there will be no pagination.
  • The template is not used correctly.paginationTagMake sure you have added the examples provided in the document correctly.{% pagination pages with show="5" %}...{% endpagination %}And the code blocks inside them.pagesVariable name andtagDataListThe outputpagesMatch the objects.

Related articles

How to use the `tagDetail` tag to get the detailed information of a Tag, such as description and link?

In AnQi CMS, tags (Tag) are an important tool for organizing content, improving SEO, and enhancing user experience.Sometimes, we need not only to list tags, but also to display detailed information about a specific tag on the page, such as its description, link, and even Logo.At this moment, the `tagDetail` tag comes into play, helping us easily obtain this data.

2025-11-08

How to call the Tag list of the specified document in AnQiCMS template?

In AnQiCMS, tagging content (Tag) is an effective way to enhance content organization and user experience.These tags not only help search engines better understand the page theme, but also guide users to discover more related content.When you need to display the Tag list associated with a specific document in a template, AnQiCMS provides an intuitive and powerful `tagList` tag to make this operation very simple.

2025-11-08

How to add and manage multiple Tag tags in AnQiCMS?

In a content management system, effectively organizing and presenting information is the key to improving user experience and search engine performance.AnQiCMS provides a flexible Tag feature, which allows for more refined categorization of content, making it easier for users to quickly find content of interest and also provides strong support for website SEO optimization.This article will provide a detailed introduction on how to add and manage multiple Tag tags in AnQiCMS, and discuss its practical value in content operation.

2025-11-08

How can keyword library management in AnQiCMS's SEO tool help optimize website content?

In the increasingly fierce online competition, optimizing website content is the key to attracting and retaining users.For operators who want to stand out in search engines and continuously obtain high-quality traffic, a set of efficient SEO tools is undoubtedly a powerful assistant.AnQiCMS as an enterprise-level content management system provides many practical functions in SEO, among which keyword library management is the core tool for us to optimize website content and improve search engine performance. Imagine your website as a library, and keywords are like indexes guiding readers to the books you provide.

2025-11-08

What is the difference between the `{{variable}}` and `{% tag %}` syntax in AnQiCMS templates?

When using Anqicms to build a website, templates are the key to dynamic content display.We often see two special syntax structures in template files: `{{variable}}` and `{% tag %}`.Although they are all related to the display and processing of data, they play different roles and have different usage methods.Understanding the difference between them is the first step in efficiently using the Anqi CMS template.

2025-11-08

How to define and use custom variables in AnQiCMS templates, such as the `{% with %}` tag?

In the template design of AnQi CMS, we often encounter scenarios where we need to temporarily store or pass data.In order to make the template code clearer, easier to read, and more powerful, AnQi CMS provides the mechanism for defining and using custom variables, the most commonly used of which are the `{% with %}` tag and the `{% set %}` tag.They can help us handle data flexibly in templates, avoiding repeated calculations or passing complex objects.

2025-11-08

How does AnQiCMS's 'Full Site Content Replacement' feature efficiently handle content strategy adjustments?

Today, with the increasing refinement and diverse strategies of content operation, how to adjust website content efficiently and accurately is a challenge facing every website operator.When brand information is updated, external link adjustments, or SEO strategy iterations occur, manually modifying thousands of contents on the website one by one is not only time-consuming and labor-intensive, but also prone to errors.Fortunately, AnQiCMS provides an extremely powerful tool - the "Full Site Content Replacement" feature, which can help operators with amazing efficiency and accuracy to deal with various content updates and strategy adjustments, and become a "secret weapon" for content management strategy adjustments.###

2025-11-08

How to configure the pseudo-static rules in AnQiCMS to optimize URL structure and include categories, model aliases?

Building a clear, search engine-friendly URL structure in AnQiCMS is a very important aspect of website operation.By reasonably configuring the pseudo-static rules and cleverly integrating categories and model aliases, not only can it enhance the user experience, but it can also significantly optimize the website's SEO performance.AnQiCMS as a high-performance content management system provides flexible pseudo-static features, allowing us to easily achieve these goals.The importance of optimizing URL structure Imagine you visit a website and see this kind of link: `example

2025-11-08