How to get and display the associated document list based on a specific tag of `tagDataList`?

Calendar 👁️ 69

In Anqi CMS, tags are not just a supplementary tool for content management, but also a powerful tool for connecting different thematic content, improving the internal link structure of the website, and optimizing the user experience. When you want to display a list of all documents related to a specific tag on a specific page of the website, such as a special topic page, a tag cloud page, or the sidebar of a specific article,tagDataListTags are your best choice.

This article will delve deeper intotagDataListHow tags can flexibly retrieve and display associated document lists based on specific tags, helping you better utilize AnQi CMS for content operation.

tagDataList: The core bridge connecting content and tags

In AnQi CMS,tagDataListThe core function of the tag is to filter all documents marked with the specified tag ID and display these documents in a list format.This is crucial for building personalized content aggregation pages, enhancing the exposure of certain thematic content, as well as improving the browsing depth of users on the website.

UsetagDataListWhen labeling, the template code is usually organized like this: {% tagDataList archives with tagId="1" %}. Here,archivesThis is a custom variable name used to store the document list collection obtained from the database.You can specify any meaningful name as needed.Then, you can pass through oneforto loop througharchivesFor each document, extract information such as document title, link, introduction, publication time, and thumbnail images for display.

It is worth noting that,tagDataListEach document object obtained has rich field information, for example: document ID (Id), Title (Title) SEO title (SeoTitle) and link (Link), Description (Description), Category ID (CategoryId), Page views (Views), Cover thumbnail (Thumb), Creation time (CreatedTimeetc. These fields are enough to meet your various needs for front-end display.

Deep understandingtagDataListparameters

tagDataListThe tag provides multiple parameters, allowing you to accurately control the scope and display method of the documents obtained:

  • tagId(Tag ID):This istagDataListThe most critical parameter of the tag. It specifies the document list under which tag you want to retrieve.This ID can be found on the 'Content Management' -> 'Document Tags' page in the AnQi CMS backend.If you are currently on a tag detail page (for example, the URL contains an ID or alias of a tag), and have not explicitly specifiedtagId,tagDataListThe tag will intelligently automatically read the tag ID of the current page. Of course, you can also go through{% tagDetail with name="Id" %}Such a tag to dynamically get the ID of the current tab and then assign it totagIdThe parameter to achieve more flexible calling.

  • moduleId(Model ID):AnQi CMS supports flexible content models, such as the "Article" model (usually ID 1), "Product" model (usually ID 2), and so on. If you only want to display documents associated with a specific content model, such as only displaying documents of the "Article" model, you can setmoduleId="1"Filter. This is very useful to avoid confusion in displaying different types of content.

  • order(Sort method):The order of content is crucial for user experience and information delivery.orderThe parameter allows you to customize the sorting rules of the document. Common sorting methods include:order="id desc"(Sorted by ID in reverse order, usually indicating the most recent release),order="views desc"(Sorted by view count, displaying the most popular documents),order="sort desc"(Sorted by custom backend in reverse order) etc. If you do not specify this parameter, the system will usually display according to the default custom sorting rules.

  • limit(Number displayed):You can control how many documents are displayed at one time. For example,limit="10"Only the first 10 documents will be displayed. In some cases, you may need to skip the first few and start displaying from the middle, in which case you can useoffsetpattern, such aslimit="2,10"Represents starting from the second item and getting 10 items.

  • type(List type):This is a very important parameter, which determines whether the document list is displayed in a simple list form or prepared for pagination. When you set it totype="list"then,tagDataListit will directly output the specifiedlimitThe number of documents. When you set it totype="page"it will prepare the data for subsequent pagination tagspaginationenabling you to easily implement a document list display with page numbers.

  • siteId(Site ID):AnQi CMS supports multi-site management. If you have created multiple sites in the background and want to call the label associated documents of another site within a site, you can specifysiteIdTo implement. But in most single-site operation scenarios, it is usually not necessary to set this parameter.

Practice: Applying in templatestagDataList

Let's understand through several specific template code examples.tagDataListactual application.

Example one: Display the latest 5 documents under a fixed tag

Assuming you have a tag with ID '1' that you want to display the latest 5 documents under it on the homepage or sidebar:

<div class="tag-related-articles">
    <h3>“热门话题”标签下的最新文章</h3>
    <ul>
        {% tagDataList archives with tagId="1" order="id desc" limit="5" %}
            {% for item in archives %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {% if item.Thumb %}<img src="{{ item.Thumb }}" alt="{{ item.Title }}">{% endif %}
                        <h4>{{ item.Title }}</h4>
                        <p>{{ item.Description|truncatechars:80 }}</p>
                        <small>发布于: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</small>
                    </a>
                </li>
            {% empty %}
                <li>当前标签下没有找到任何文档。</li>
            {% endfor %}
        {% endtagDataList %}
    </ul>
</div>

This code will query the latest 5 documents with tag ID 1 and display their titles, links, thumbnails, summaries, and publication dates in a list.truncatechars:80It is a filter used to truncate the document summary to 80 characters and add an ellipsis.

Example two: Display the paginated document list under the tag on the tag detail page.

When a user visits a dedicated tag page (for example/tag/seo), we usually want to display all documents related to the "SEO" tag and provide pagination. In this case,tagDataListoftype="page"Parameters come into play:

”`twig {% tagDetail currentTag with name=“Id” %} {# Get the ID of the current tag page #} {% if currentTag %}

<div class="tag-documents-list">
    <h1>标签:{% tagDetail with name="Title" %}</h1>
    <p>描述:{% tagDetail with name="Description" %}</p>

    {% tagDataList archives with tagId=currentTag type="page" limit="10" %}
        {% for item in archives %}
            <article>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    <h2>{{ item.Title }}</h2>
                    <p>{{ item.Description|truncatechars:150 }}</p>
                    <small>浏览量: {{ item.Views }} | 发布于: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</small>
                </a>
            </article>
        {% empty %}
            <p>当前标签下没有找到任何文档。</p>
        {% endfor %}
    {% endtagDataList %}

    <div class="pagination-container">
        {% pagination pages with show="5" %}
            <ul>
                {% if pages.FirstPage %}
                    <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
                {% endif %}
                {% if pages.PrevPage %}
                    <li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
                {% endif %}
                {% for pageItem in pages.Pages %}
                    <li class="{% if pageItem.IsCurrent %}active{% endif %}"><a href="{{pageItem.Link}}">{{pageItem.Name}}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li><a href="{{pages.NextPage.Link}}">下一页</a></li>
                {% endif %}
                {% if pages.LastPage %}
                    <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
                {% endif %}
            </ul>
        {% endpagination %}
    </div>
</div>

{% else %}

<p>未能找到相关标签信息

Related articles

How does the `tagDetail` tag display the name, description, and other properties of a single tag?

In website content management, tags (Tag) play a multiple role in connecting content, optimizing user experience, and improving search engine visibility.A well-managed tag system not only helps visitors quickly locate the information they are interested in, but also conveys the structured information of the website content to search engines, thereby effectively improving SEO.AnQiCMS (AnQiCMS) fully understands the importance of tags and therefore provides a powerful and easy-to-use `tagDetail` tag, allowing you to flexibly obtain and display detailed information about individual tags.

2025-11-07

How does the AnQiCMS `tagList` tag display all associated tags of the document?

## Easily display document-related tags: In-depth analysis of AnQiCMS's `tagList` tag In content management, tags (Tag) play a crucial role.They can not only help us better organize content and improve the internal link structure of the website, but also play a huge role in search engine optimization (SEO), making it easier for users and search engines to find relevant information.AnQiCMS has fully considered this point and provided a flexible and powerful tag management system.Among, `tagList`

2025-11-07

How does the `pageDetail` tag display the detailed content of a single page, such as the 'About Us' page?

In Anqi CMS, single pages (such as "About UsTo present the detailed content of these single pages on the website frontend, we will use a very core and practical template tag——`pageDetail`.This tag helps us accurately extract and display various information on a specified single page, ensuring the flexibility and accuracy of content presentation.

2025-11-07

How does the `pageList` tag display all the titles and links of the individual pages of the website?

In Anqi CMS, using the `pageList` tag to display the titles and links of all single pages is a very common and practical need in website layout and navigation settings.Whether it is used for website footer navigation, sidebar link list, or building a simple HTML site map, the `pageList` tag can help us efficiently achieve these functions. ### Understanding AnQi CMS Single Page Firstly, let's briefly review the "single page" in AnQi CMS.In the Anqi CMS backend management, there is a special "Page Resources" module

2025-11-07

How to flexibly construct and display the top, side, or bottom navigation menu of a website using the `navList` tag?

When building a fully functional website, a clear and intuitive navigation menu is undoubtedly one of the core elements of user experience.AnQiCMS provides a powerful and flexible `navList` tag, allowing users to easily create and manage the top, side, or bottom navigation menus of the website, meeting different layout and content display needs. ### `navList` Tag Basic Usage The `navList` tag is a key tool in the AnQiCMS template engine used to obtain the website navigation list.

2025-11-07

How to generate and display a clear hierarchical breadcrumb navigation on the AnQiCMS page using the `breadcrumb` tag?

In website operations, a clear navigation path is crucial for improving user experience and search engine optimization (SEO).When we browse websites, a concise and clear path can help us quickly locate and understand our current position.

2025-11-07

How to call and display the website name, Logo, filing number, and other global configuration information using the `system` tag?

Building a website in Anqi CMS, the basic information of the page, such as the website name, Logo, filing number, copyright information, etc., is an important element in forming the overall style and professionalism of the website.This information often needs to be managed uniformly and flexibly called at various corners of the website.AnQi CMS provides the `system` tag, which is like a central console that allows us to easily call and display these global configuration information.

2025-11-07

How to uniformly display the website's contact information, phone number, and email address with the `contact` tag?

How to efficiently manage and uniformly display a company's contact information, such as contacts, phone numbers, email addresses, and addresses, is a seemingly simple problem that often causes headaches.Imagine if this information were scattered across various pages of a website, and once an update is needed, you would have to search and modify each one individually. This is not only time-consuming and labor-intensive, but it is also prone to omissions or inconsistencies.Fortunately, AnQiCMS (AnQiCMS) provides an elegant solution - the `contact` tag, which helps us easily manage and flexibly display contact information.

2025-11-07