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.