How to retrieve all documents under a specific Tag and implement pagination using `tagDataList` tag?

Calendar 👁️ 51

In the vast field of content operation, tags (Tags) play a crucial role.They can not only thematize and structure scattered content, but also guide users to conduct in-depth exploration, improve the efficiency of content discovery, and enhance the overall user experience of the website.As an experienced website operations expert, I am well aware of AnqiCMS (Anqi CMS)'s powerful capabilities in tag management and content display.Today, let's delve into a very practical tag in AnqiCMStagDataListHow can you cleverly use it to get all documents under a specific tag and elegantly implement pagination display.

Understand the tag withtagDataListthe core role

First, let's clarify the position of the tag in AnqiCMS.Tags are a way to categorize and index website content, providing a more flexible way to aggregate related topics across different content models (such as articles, products).On the AnqiCMS backend, you can easily manage these tags, including creating, editing their names, descriptions, custom URLs, and more, which in文档标签使用帮助detailed explanations in the document.

When we need to display all the articles, tutorials, or products related to "SEO optimization" on a front-end page, such as a detailed page of a "SEO optimization" tag,tagDataListThe tag has become our helpful assistant. Its main responsibility is to extract all related document data based on the specified tag ID or the current page context.

tagDataListThe tag provides multiple parameters, allowing us to finely control the retrieval of content:

  • tagId: This is the core parameter used to specify which label's documents you want to retrieve. Usually, when you are on the AnqiCMS tag detail page (such as/tag/seo.html) Use this tag when the system will intelligently automatically identify the tag ID of the current page, you do not need to specify it manually. However, if you want to call the content under a specific tag at a certain location on a non-tag detail page (such as the home sidebar), you need to specify it explicitlytagId="1"(Assuming the tag ID is 1).
  • moduleId: If you only want to retrieve documents under a specific content model (for example, only retrieve documents under the article model and ignore the product model), you can usemoduleId="1"(Assuming the article model ID is 1). This makes the content display more focused.
  • order: Used to set the document sorting method, you can sort by the most recent publish time (id desc), Page views (views desc) or custom sorting from the backend (sort desc) to display content.
  • limit: Defines the number of documents displayed per page, which is one of the key parameters for pagination. For example,limit="10"This means showing 10 documents per page.
  • type="page":This is the core of implementing pagination.Whentypeis set topagethen,tagDataListIt will not only return the document data of the current page but also pass the complete page information to the template for the pagination tags of AnqiCMSpaginationusage.

Elegantly implement pagination display of tag pages

When the number of documents under a specific tag is large, loading all the content at once will not only affect the page loading speed but also cause user browsing fatigue.Therefore, implementing pagination is an inevitable choice to enhance user experience and website performance.AnqiCMS's template engine provides seamless support for this.

Implement pagination mainly involves two steps:

  1. UsetagDataListGet the paginated document data: You need to assigntagDataListExplicitly specify in the tagtype="page"andlimitParameters. For example:

    {% tagDataList archives with type="page" limit="10" %}
        {# 在这里循环显示当前页的文档列表 #}
        {% for item in archives %}
            <li>
                <a href="{{ item.Link }}">{{ item.Title }}</a>
                <p>{{ item.Description }}</p>
                <span>发布时间:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </li>
        {% empty %}
            <li>当前标签下暂无文档。</li>
        {% endfor %}
    {% endtagDataList %}
    

    here,archivesthe variable will contain all the documents on the current page.emptyPart then handles the case where there are no documents under the label, providing a friendly prompt.

  2. BypaginationThe tag generates pagination navigation: Then紧接着tagDataListAfter the label, you can usepaginationTags to render pagination navigation.paginationthe tag will automatically readtagDataListThe page context information passed generates navigation links such as 'Home', 'Previous page', 'Next page', 'Last page', and page number.

    paginationThe tag accepts an important parameter:showIt is used to control the number of page numbers displayed in the middle. For exampleshow="5"It will display 5 page number links before and after the current page.

    paginationThe label will provide an interface for external accesspagesVariable that contains all pagination information, for example:

    • TotalItemsTotal number of documents:
    • TotalPagesTotal number of pages:
    • CurrentPageCurrent page:
    • FirstPage,LastPage,PrevPage,NextPage: Represent the objects for home page, last page, previous page, and next page, includingName(Link Name) andLink(Link Address).
    • Pages: An array containing detailed information about the middle page numbers, each element also containsNameandLink, as well asIsCurrent(whether it is the current page).

    Combining the abovetagDataListcode, the complete pagination implementation is as follows:

    {# 假设您正在 tag/list.html 或 tag/index.html 模板中 #}
    <div class="tag-documents">
        <h1>当前标签:{% tagDetail with name="Title" %}</h1>
    
        {# 获取特定标签下的文档列表并启用分页 #}
        {% tagDataList archives with type="page" limit="10" %}
            <ul>
                {% for item in archives %}
                    <li>
                        <a href="{{ item.Link }}">
                            <h3>{{ item.Title }}</h3>
                            <p>{{ item.Description|truncatechars:100 }}</p>
                            <small>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }} | 浏览:{{ item.Views }}</small>
                        </a>
                    </li>
                {% empty %}
                    <li style="text-align: center; padding: 20px;">当前标签下暂无相关文档。</li>
                {% endfor %}
            </ul>
        {% endtagDataList %}
    
        {# 渲染分页导航 #}
        <div class="pagination-nav">
            {% pagination pages with show="5" %}
                <ul class="pagination-list">
                    {% if pages.FirstPage %}
                        <li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
                            <a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
                        </li>
                    {% endif %}
    
                    {% 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 %}
    
                    {% if pages.LastPage %}
                        <li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
                            <a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
                        </li>
                    {% endif %}
                </ul>
                <div class="pagination-info">
                    总计 {{ pages.TotalItems }} 条文档,共 {{ pages.TotalPages }} 页,当前第 {{ pages.CurrentPage }} 页。
                </div>
            {% endpagination %}
        </div>
    </div>
    

This code first utilizestagDataListRetrieve and loop through the documents under the current tag and set 10 items per page. Then,paginationBased on the tagtagDataListThe page data is generated, outputting a complete pagination navigation structure. By addingactiveclass, you can easily provide clear visual feedback to users through CSS.

Operational Practices and Precautions

  • Template File Conventions: Typically, the template files for displaying the document list under the tag are placed in `/template/{Your template directory}/tag/

Related articles

How `tagList` tags display the related Tag list of the specified document?

As an experienced website operations expert, I know that how to flexibly and effectively organize and display content in a content management system is the key to improving user experience and search engine optimization (SEO).AnQiCMS (AnQi CMS) offers many powerful functions in this aspect, and the `tagList` tag is an important bridge to connect content and enhance discoverability.Today, let's delve into how to use the `tagList` tag in AnQiCMS to accurately display the associated tag list of a specified document.### Fine-grained content management

2025-11-06

How to get the link, Logo image, and document count in the `categoryList` loop?

As an experienced website operations expert, I am well aware of the importance of an efficient and flexible content management system for daily operations.AnQiCMS with its high-performance architecture based on the Go language and the friendly syntax of the Django template engine, provides us with great convenience.Today, let's explore a very practical technique in website frontend display: how to elegantly obtain the links, Logo images, and the number of documents under each category in the `categoryList` loop.

2025-11-06

how the `categoryList` tag implements nested hierarchical display of multi-level categories?

Sure, as an experienced website operations expert, I am happy to deeply analyze how to implement nested display of multi-level categories in the `categoryList` tag of AnQi CMS and transform it into an article that is easy to understand and practical. --- ## AnQi CMS `categoryList` Tag: Easily Implement Nested Display of Multi-level Categories, Making the Website Structure Clear and Orderly A clear classification system is crucial for user experience (UX) and search engine optimization (SEO) in website operations.

2025-11-06

How to get all top-level categories under a specified model for the `categoryList` tag?

Anqi CMS, as an efficient and customizable enterprise-level content management system, provides great flexibility in content organization and display.Among them, skillfully using template tags is the key to leveraging its potential.Today, let's delve into how to use the `categoryList` tag to accurately retrieve all top-level categories under a specified content model, which is crucial for building clear website navigation, content modules, or product display pages.

2025-11-06

How to use the `pageDetail` tag to get detailed content and images of a single page (such as "About Us")?

In website operation, pages like "About Us" and "Contact Us" are indispensable, as they carry important information such as corporate culture, contact information, and service introduction.How to present these carefully prepared contents efficiently and beautifully on the front end of a website is a skill that every website operator needs to master.For users using AnQiCMS, the `pageDetail` tag is the key tool to achieve this goal.

2025-11-06

How to build a multi-level website navigation menu using the `navList` tag and support dynamic display of categories or document links?

As an experienced website operations expert, I am well aware of the importance of a clear and efficient website navigation system for improving user experience, guiding content consumption, and optimizing search engine rankings (SEO), which is self-evident.In AnQiCMS (AnQiCMS) such a well-designed content management system, building flexible and variable navigation menus, and making them able to intelligently display dynamic content, is the key to operators achieving fine-grained content layout.

2025-11-06

How to use the `breadcrumb` tag in the AnQiCMS template to generate breadcrumb navigation?

As an experienced website operations expert, I know that a user-friendly and SEO-optimized website cannot do without a clear navigation structure, and breadcrumb navigation is the key link in this regard.It can not only help users understand their current location, improve the usability of the website, but also provide clear website structure signals for search engines.In AnQiCMS, integrating and using breadcrumb navigation is very simple and efficient, which is mainly due to its built-in `breadcrumb` tag. Today

2025-11-06

How does the `stampToDate` tag format timestamps into any custom date and time format?

## Mastering AnqiCMS `stampToDate`: Easily Customize Time Display Format The way time information is presented is crucial in the daily work of content operation.Whether it is the release date of an article, the time a product is listed, or the moment a comment is submitted, a clear and readable date and time format can greatly enhance the user experience.However, we often get a series of difficult-to-understand Unix timestamps from the database - like the number `1609470335`. Don't worry

2025-11-06