How to implement sorting by 'latest documents' or 'most viewed' in AnQiCMS's `tagDataList`?

Calendar 👁️ 63

As an experienced website operations expert, I know how important it is to effectively display the 'latest documents' and 'most viewed' content in a massive amount of information to attract users and enhance website activity.AnQiCMS (AnQiCMS) with its powerful template system and flexible tag functions, provides us with the tool to achieve this goal.Today, we will delve deeply into AnQiCMStagDataListHow to cleverly implement these two common sorting requirements of tags.

AnQiCMS intagDataListTag: A powerful tool for content operation.

First, let's understandtagDataListTag. In AnQiCMS,tagDataListTags are specifically used to retrieve the document list associated with a specific “Tag”. This means that if you want to display the latest articles or the most popular products under a specific theme,tagDataListTags are your first choice. Not only can they retrieve content, but they also provide a rich and intuitive sorting mechanism, making content presentation smarter.

Use cleverlyorderParameter: Unlock the "Latest Documents" and "Most Viewed".

tagDataListThe core of the tag lies in its powerful.orderThe parameter allows us to specify the document display order, making it easy to achieve common sorting requirements such as "latest documents" and "most viewed documents".

Implement "Latest Documents" sorting

To display the "latest documents" under a tag, we usually want the content to be arranged from new to old by publishing time. In AnQiCMS, the unique identifier ID of the document (id)usually increases automatically, which means that the document with a larger ID was published later. Therefore, we can sort theidfield in descending order(desc)to achieve this purpose.

we cantagDataListSet this way in the tagorderparameters:order="id desc"This will inform AnQiCMS to return data in descending order of document ID, naturally, your website visitors will see the latest content.

For example, to display the 5 latest articles under a specific tag on your tab page, you can write the template code like this:

{% tagDataList latestArticles with tagId="您的标签ID" order="id desc" limit="5" %}
    <div class="latest-articles-list">
        <h3>最新文章</h3>
        <ul>
            {% for article in latestArticles %}
            <li>
                <a href="{{ article.Link }}">{{ article.Title }}</a>
                <span>发布日期: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
            </li>
            {% endfor %}
        </ul>
    </div>
{% endtagDataList %}

In this code block:

  • tagId="您的标签ID": Replace with the actual tag ID, or if you use it on the tag detail page,tagDataListit will automatically get the tag ID of the current page.
  • order="id desc"This is the key to implementing the 'Latest Documents', ensuring that the latest content is displayed at the top.
  • limit="5"Limit to displaying only the latest 5 articles.
  • stampToDate(article.CreatedTime, "2006-01-02")This is a very useful time formatting function that converts the document's creation timestamp into a readable date format.

Implement 'Most Viewed' sorting

For the content with the most views, we are concerned with the popularity of the content. AnQiCMS records the number of views for each document (views)Data. Therefore, to display the most popular content, we can sort theviewsfield in descending order.

IntagDataListIn the tag, we willorderthe parameter toorder="views desc"This way, the system will return the content according to the document's viewing volume from high to low, allowing you to see your popular content at a glance.

Follow the above example, if you want to display the top 5 articles under a specific tag:

{% tagDataList popularArticles with tagId="您的标签ID" order="views desc" limit="5" %}
    <div class="popular-articles-list">
        <h3>热门文章</h3>
        <ul>
            {% for article in popularArticles %}
            <li>
                <a href="{{ article.Link }}">{{ article.Title }}</a>
                <span>浏览量: {{ article.Views }}</span>
            </li>
            {% endfor %}
        </ul>
    </div>
{% endtagDataList %}

Here:

  • order="views desc"This is the key to achieving the most views, ensuring that the most popular content is at the top.
  • article.Views: Directly display the document's page view data.

By making such simple parameter adjustments, you can flexibly display various sorted content lists in different areas of the website, greatly enhancing user experience and the discoverability of content.

More advanced usage and tips

In addition to basic sorting,tagDataListIt also supports combining other parameters to achieve more fine-grained control:

  • Limit the Display Quantity: Use.limit="N"Parameters, you can accurately control the number of items displayed in the list, for examplelimit="10". You can even specify the start position and quantity, such aslimit="2,10"means starting from the 2nd record and taking 10.
  • specify the content model: If you want to get content with a specific tag under a certain content model (such as an article model or product model), you can usemoduleIdparameters such asmoduleId="1"(The article model usually has an ID of 1).
  • Paginated displayIf the content is too much and you want to display it in pages, you cantypethe parameter totype="page"then combine it with AnQiCMS'spaginationtags to implement pagination.

Benefiting from the clear template syntax and powerful function design of AnQiCMS, website operators do not need to delve into complex backend code, and can achieve a variety of content display strategies by adjusting template tag parameters.This not only improves work efficiency, but also makes content operation more skillful.

Frequently Asked Questions (FAQ)

  1. Question: Besides,id descandviews desc,tagDataListWhat sorting methods does it support?Answer:tagDataListSupports descending order sorting according to custom sorting fields in the background, i.e.order="sort desc". ThissortField allows you to manually adjust the document priority in the background to achieve more flexible personalized sorting requirements.

  2. Ask: Can I directly usetagDataListto get the latest or hottest list of all documents, rather than documents under a specific tag?Answer: No.tagDataListIn accordance with its name, it is for the 'Label Data List' service, it will always be associated with one or more labels. If you want to getThe entire siteThe latest or most popular document, not limited to a specific tag, you should use the AnQiCMS providedarchiveListtag, which also supportsorder="id desc"andorder="views desc"parameter, and there is no need to specifytagId.

  3. Ask: If my document does not have view count data,order="views desc"how will it perform?Answer: If the document does not have view count data (i.e.],viewsthe field is 0 or empty), they are inviews descDocuments will be sorted after those with views, and their relative order will be based on other default sorting rules (usually id desc)to decide. It is recommended to ensure that all your documents have the correct page view statistics to obtain accurate "hot" sorting results.

Related articles

Can the `tagDetail` tag retrieve the 'content' field of Tag and render it as HTML?

As an experienced website operation expert, I know that content is the soul of the website, and how to efficiently and flexibly manage and present these contents is the value of excellent tools like AnQiCMS (AnQiCMS).Today, let's discuss a practical question about AnQiCMS template tags: Can the `tagDetail` tag retrieve the 'content' field of Tag and render it as HTML?There is no doubt that the answer is **affirmative**. The `tagDetail` tag of Anqi CMS can not only obtain the "content" field of Tag

2025-11-07

How to configure the custom URL of the Tag to take effect in the pseudo-static rules?

AnQi CMS as an experienced website operation expert, I know that the structure of URL in a content management system is crucial for the SEO and UX of a website.A clear and meaningful URL can not only help search engines better understand the content of the page, but also make it easy for visitors to understand at a glance.Today, let's delve into how to configure the "Custom URL for Tag" in Anqi CMS in the pseudo-static rules to make it truly effective, making your website's Tag page more competitive.### AnQi CMS and URL Optimization

2025-11-07

How to customize AnQiCMS's Tag detail page template (`tag/list.html`)?

As an old veteran in website operation for many years, I know that every detail of a page may affect the overall performance of the website, especially in SEO and user experience.AnQiCMS is an efficient and flexible content management system that provides us with powerful customization capabilities, allowing us to make each page unique.

2025-11-07

How to apply the `tagDetail` tag's 'Logo' field on the Tag detail page?

As an experienced website operations expert, I am well aware of how to fully utilize each field in a content management system to transform it into an effective tool that attracts users and enhances the value of the website.AnQiCMS (AnQiCMS) with its flexible and versatile characteristics, provides us with a lot of room to maneuver.Today, let's talk about the `tagDetail` tag, which has a seemingly ordinary but limitless potential field - 'Logo', and see how it shines on the Tag detail page.

2025-11-07

How to set SEO optimization for the document tag (Tag) of AnQi CMS?

As an experienced website operation expert, I know how to fine-tune every detail in a highly efficient and powerful content management system like AnQiCMS in order to maximize its SEO potential.Today, let's delve into the document tag (Tag) feature of AnQiCMS, and how to make these little tags play a huge role in search engine optimization through clever settings.

2025-11-07

What is the impact of the "SEO title", "tag keywords", and "tag description" on search engine inclusion?

Unlock the SEO potential of AnQiCMS Tag: In-depth analysis of the impact of "SEO title", "tag keywords", and "tag description" on inclusion In the practice of website operation, Search Engine Optimization (SEO) has always been the core to enhance website visibility and attract natural traffic.AnQiCMS is an enterprise-level content management system built with Go language, which fully considers SEO-friendly features from the very beginning, and has built-in advanced SEO tools to help users efficiently manage and promote content. Among them

2025-11-07

How to set up a standard URL structure for AnQiCMS Tag detail page?

As an experienced website operations expert, I am well aware that a standardized and clear URL structure is crucial for a website's search engine optimization (SEO) and user experience.In a highly efficient and flexible content management system like AnQiCMS, setting an appropriate URL for the Tag detail page not only improves the crawling efficiency and keyword ranking of search engines, but also makes it easy for users to understand the content of the page, enhancing the overall professionalism of the website.### AnQi CMS and URL normalization

2025-11-07

How does the `tagDetail` tag ensure that the TDK information on the Tag page is accurate and correct?

In today's highly competitive online environment, a website's search engine optimization (SEO) performance is directly related to its visibility and traffic.While TDK (Title, Description, Keywords) information is the 'face' of a web page displayed on search engine results pages, its accuracy and attractiveness are crucial.For Tag (tag) pages such as these dynamic content aggregation pages generated by the system, ensuring the accuracy and correctness of their TDK information is often a major challenge faced by website operators

2025-11-07