How to filter and display documents based on multiple category IDs for the `archiveList` tag?

Calendar 👁️ 68

As an experienced website operations expert, I know that the flexibility of the content management system is crucial for efficient operation.AnQiCMS (AnQiCMS) takes advantage of its powerful template tag system, providing us with great convenience.archiveListLabel, filter and display documents based on multiple category IDs to create more targeted and attractive content modules.

Flexible filtering: AnQiCMSarchiveListThe application of multi-class ID tags

In website content operation, we often need to display articles, products, or other documents from multiple related categories on a specific page.For example, you may want to display the contents of two categories, such as "Latest News" and "Hot ProductsIf only the content of each category can be called one by one, it is not only inefficient but also difficult to integrate and display the content in an interlaced manner.

AnQiCMS'archiveListThe tag is exactly for solving this kind of need.It is a feature-rich document list call tag that can help us flexibly extract and display various types of documents.One of its core advantages is the strong support for classification IDs, especially when dealing with 'multi-class' filtering, showing the elegance of its design.

The key to implementing the screening and display of documents based on multiple classification IDs isarchiveListlabel'scategoryIdthe parameters. You no longer need to write one for each classificationarchiveListCall, but you can also pass multiple category IDs separated by commas to this parameter.

For example, assume that your 'Latest News' category ID is5,“Hot Products” category ID is12,and the “Technical Tutorial” category ID is8。If you wish to display the latest documents of these three categories in the same area, yourarchiveListHow to label it:

{% archiveList archives with categoryId="5,12,8" type="list" limit="10" order="id desc" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description|truncatechars:80}}</p>
            <span>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </a>
    </li>
    {% empty %}
    <li>当前暂无符合条件的文档。</li>
    {% endfor %}
{% endarchiveList %}

In this code block,categoryId="5,12,8"Command to query documents under categories with IDs 5, 12, or 8 in AnQiCMS.type="list"Means we do not need pagination,limit="10"It limited to display only the latest 10 documents, andorder="id desc"Ensured that the documents are sorted in descending order by document ID, usually representing the most recently published content.forThe loop is used to iterate through these filtered documents, displaying their titles, descriptions, and publication dates one by one. If no documents meet the criteria,emptyBlock hints will appear, providing users with friendly feedback.

Combined with other parameters, create a more accurate content presentation.

archiveListThe power of the tag is not just limited to this. When you need to control the display content more finely, you cancategoryIdcombine the parameters with other parameters to achieve more accurate filtering and sorting.

  1. Specify content model (moduleId): AnQiCMS supports custom content models. If you have a "article model" (ID may be 1) and a "product model" (ID may be 2), and you want to display only articles under specific categories and not products, you cancategoryIdincreased on the basis ofmoduleIdParameter.{% archiveList archives with moduleId="1" categoryId="5,8" type="list" limit="10" %}This will only filter documents from the categories with IDs 5 and 8 in the article model.

  2. excluding specific categories(excludeCategoryId): Sometimes you may want to display all documents under a specific content model but exclude a few unrelated categories.excludeCategoryIdParameters can help you achieve this.{% archiveList archives with moduleId="1" excludeCategoryId="6,9" type="list" limit="15" %}This command will list the latest 15 articles from all article models, excluding categories with IDs 6 and 9.

  3. Multiple sorting (order): In addition to sorting by ID (i.e., publication time), you can also sort by document views (views desc), and custom sorting in the background (sort descSort in this way. Combining multi-class filtering can help you find the most popular or most relevant documents across multiple categories.{% archiveList archives with categoryId="5,12,8" type="list" limit="10" order="views desc" %}This will display the top 10 documents with the highest views from these three categories.

  4. Recommended attribute filtering (flag): AnQiCMS provides various recommended attributes for documents, such as "Headline[h]", "Recommended[c]", "Slideshow[f]", etc. If you want to filter documents marked as "Recommended" across multiple categories, you can useflagParameter.{% archiveList archives with categoryId="5,12,8" type="list" limit="5" flag="c" %}This will select 5 documents marked as 'recommended' from these three categories.

Through the flexible combination of these parameters,archiveListTags can help you build highly customized content display modules, whether it's news aggregation, product lists, or special topic recommendations, they can easily handle them, greatly improving the efficiency of content operations and the attractiveness of website content.

Tips for operation: Rational planning of category ID and content model

To give full play toarchiveListThe powerful function of tags, the content planning in the early stage is crucial.

  • Clear classification systemIn the background, establish a clear and logical classification structure, assign clear responsibilities to each category, which is helpful for you to quickly and accurately locate content when usingcategoryIdparameters.
  • A unified content modelFor the same type of content, try to use the same content model. This allows you tomoduleIdexercise overall control and manage the categories under it uniformly when necessary.
  • utilize recommended attributesTake full advantage of the documentation'sflagProperties, marking documents that are important, recommended, or have special display requirements can achieve more flexible filtering.

In short,archiveListThe combination of tags with multiple category IDs is a great tool for AnQiCMS content operation.Master its usage and combine it with actual operational needs for parameter configuration, and you will be able to manage and present website content more efficiently and accurately.


Frequently Asked Questions (FAQ)

Q1: Can I usecategoryIdAre the parameters filtering from differentmoduleIdmultiple categories?

A1: No,categoryIdThe parameters are based on a singlemoduleId. This means you cannot be in the samearchiveListSpecify at the same time in the tagmoduleId="1"And the classification ID of the articlemoduleId="2"And the classification ID of the product. If you need to display multiple classification documents from different content models, you should provide eachmoduleIdUse onearchiveListtag to retrieve data, then combine or display them in blocks according to design requirements.

Q2: If I setcategoryIdHow to filter multiple categories, what is the sorting logic of the documents? For example, I have setcategoryId="5,8"and sort byid descSort, AnQiCMS first finds the latest document in categories 5 and 8 and merges them, or sorts globally among all documents that meet the conditions?

A2: AnQiCMS will internally match all that meet the criteriacategoryIdThe document with condition (i.e., ID 5 or 8) as a whole dataset, then sort this complete dataset according to the specified parameter (orderThis means that if you setorder="id desc"It will return all documents from categories 5 and 8, sorted by publication date, without being followed by the "latest document of category 5" and then the "latest document of category 8".This is a global sorting that ensures the unity of the results.

Q3: I found that some documents belong to multiple categories, when I usecategoryIdparameter filtering for one category, will these documents be recalculated or displayed repeatedly?

A3: In most modern CMSs, including AnQiCMS, documents are usually designed to belong to one or more categories. When you usecategoryId="ID1,ID2"When filtering, the system will query all documents that belong to ID1 or ID2 at least.However, the final document list will be deduplicated to ensure that each document appears only once in the results.archiveListIt appears once in the result, and will not cause duplicate display.

Related articles

How to use the `archiveList` tag of AnQiCMS to get the document list under a specified content model?

AnQiCMS Content Management: The secret to accurately obtaining the document list with the `archiveList` tag As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its ability to organize and display content.In the AnQiCMS, this efficient and flexible Go language content management system, the `archiveList` tag is undoubtedly a powerful weapon in the content display process.It is not just a simple content call tag, but also a key bridge connecting your website content model with the front-end display logic.

2025-11-06

`archiveFilters` label can be combined with AnQiCMS's multilingual support to provide multilingual filtering conditions?

As an experienced website operations expert, I have accumulated rich experience in the content management and operations practice of AnQiCMS.Today, we will delve into a commonly discussed issue by users: Can AnQiCMS's `archiveFilters` tag be combined with multilingual support to provide multilingual filtering conditions?To answer this question, we need to understand the multilingual mechanism of AnQiCMS and the working principle of the `archiveFilters` tag.AnQiCMS as an enterprise-level content management system

2025-11-06

How will the `archiveFilters` tag display and handle if a document belongs to multiple filter parameter values?

## AnQi CMS `archiveFilters` tag: How will it elegantly present when a document meets multiple filter conditions?As an experienced website operations expert, I am well aware that the discoverability of content is crucial for user experience and SEO.AnQiCMS provides many powerful and flexible features in content management, among which the `archiveFilters` tag is undoubtedly a powerful tool for building advanced filtering interfaces and improving content navigation efficiency.

2025-11-06

Does the `archiveFilters` tag support controlling the sorting method for custom parameters?

As an experienced website operations expert, I have a deep understanding of AnQiCMS's functional and content operation strategies.Today, we will discuss a question that many users may be concerned about: Does the `archiveFilters` tag support controlling the sorting method of custom parameters?

2025-11-06

How to exclude documents of a specific category in `archiveList` to display accurate content?

As an experienced website operations expert, I am well aware of the importance of accurate content display for user experience and website operation efficiency.In a content management system, we often encounter the need to exclude certain specific categories of documents when generating article lists, in order to ensure the relevance and focus of the content.AnQiCMS (AnQiCMS) is an efficient and flexible content management tool that provides us with a very convenient solution.

2025-11-06

How to use the `archiveList` tag to get documents with specific recommended attributes (such as "Top Stories" or "Slideshow")?

As an experienced website operations expert, I am well aware of the core value of a content management system (CMS) in terms of its flexibility and content scheduling capabilities.AnQiCMS (AnQiCMS) boasts its efficient architecture based on the Go language and rich features, providing strong support for content operations.Today, let's delve into a very practical scenario in content operation: how to accurately obtain and display documents with specific recommendation attributes using the `archiveList` tag, such as the website's 'headlines' news or important content for the 'slideshow' carousel.

2025-11-06

How to implement sorting of the document list by views or publication time using the `archiveList` tag?

As an experienced website operations expert, I know that the core value of a content management system (CMS) lies in its flexibility and the efficiency of content presentation.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture in the Go language and a rich set of features.Today, let's delve deeply into a function that is extremely commonly used in content operation: how to use the `archiveList` tag to sort the document list by views or publication time.Content sorting seems simple, but it actually contains profound operational strategies.

2025-11-06

How to set the display quantity and offset for the `archiveList` tag in AnQiCMS to achieve pagination?

As an experienced website operations expert, I know that an efficient and flexible list display method is crucial for user experience and website performance.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template tag system.Today, let's delve into how to cleverly set the display quantity and offset using the AnQiCMS `archiveList` tag to achieve a smooth pagination effect.

2025-11-06