As an experienced website operations expert, I have a deep understanding of the powerful functions and flexible template system of AnQiCMS.In daily content operation, we often encounter the need to aggregate and display different types of content.categoryListtagsmoduleIdThe use of parameters, especially the issue of whether multiple model IDs can be specified simultaneously for joint queries.
Deep understandingcategoryListTags andmoduleIdParameters
In the template world of AnQi CMS,categoryListTags are undoubtedly one of the core tools for content aggregation and display.It allows us to conveniently retrieve and display the website's category structure, whether it's article categories, product categories, or other custom content model categories, all can be flexibly retrieved through it.moduleIdParameters are exactlycategoryListThe core of the tag, it is mainly used to specify which content model's category list you want to obtain.
The highlight of Anqi CMS is its 'flexible content model' design.This means you can create various content types according to your business needs, such as an 'article model' for publishing news blogs, a 'product model' for showcasing products, and even create 'case models', 'service models', and so on.Each category created will be bound to a specific content model.moduleIdThe role of the parameter is to accurately tellcategoryListLabel: "The article model I need to retrieve is "moduleId=1" under all categories, or "The product model I need is "moduleId=2" under all categories."
moduleIdCan the parameters achieve joint query of multiple models?
Now, let's face the core issue:categoryListTagsmoduleIdCan multiple model IDs be specified at the same time, for example?moduleId="1,2"ormoduleId="1|2"Thus, to achieve a joint query or mixed display of different content model classifications?
Based on a deep understanding of the functions and template tag syntax of AnQi CMS, my answer is: categoryListTagsmoduleIdParametersCannot directly perform a union query for different model classifications by passing multiple model IDs (e.g., separated by commas or pipe symbols).
This is mainly because the Anqi CMS is designed in such a way that each category is closely associated with only one content model.moduleIdThe intended meaning of the parameter is to explicitly specify from which "whichmoduleId="1|2|3"It is more like an exemplary expression of the 'possible values' of this parameter, suggesting that it can accept model IDs 1, 2, or 3, but does not indicate that these three IDs can be entered together for a joint query. In the actual template parsing, moduleIdIt is generally expected to receive a single integer value representing a specific content model ID.
How to implement the aggregation display of multi-model classification?
AlthoughmoduleIdThe parameter itself does not support joint queries of multiple models, but this does not mean that we cannot aggregate and display data from different models flexibly in the template. Anqi CMS provides sufficient flexibility to meet such needs, mainly including the following strategies:
make multiple calls
categoryListtagsThis is the most direct and clearest implementation. If you need to display classifications from different models in different areas of the page or according to different logic, you can use it multiple times.categoryListLabel, pass a different one each time you call itmoduleId.For example, you may want to list all article categories first in a navigation menu, followed by all product categories:
<nav class="main-navigation"> <h4>文章分类</h4> <ul> {% categoryList articleCategories with moduleId="1" parentId="0" %} {% for item in articleCategories %} <li><a href="{{ item.Link }}">{{ item.Title }}</a></li> {% endfor %} {% endcategoryList %} </ul> <h4>产品分类</h4> <ul> {% categoryList productCategories with moduleId="2" parentId="0" %} {% for item in productCategories %} <li><a href="{{ item.Link }}">{{ item.Title }}</a></li> {% endfor %} {% endcategoryList %} </ul> </nav>The advantages of this method are clear logic, easy maintenance, and each group of classification data comes from its respective model, with clear responsibilities.
Utilize
all=trueParameters retrieve all categories and perform filtering at the template level.If you need to obtainallcategories under the content model (not limited to a specific model),categoryListprovides a more direct parameter:all=truewhen you useall=truewhencategoryListignoremoduleIdparameter (if specified)moduleId, thenall=truewill only retrieve all categories under the specified model, rather than all models), returning all categories under all models. You can do this within the template byitem.ModuleIdProperties for further categorization or filtering of these categories.<nav class="all-categories-navigation"> <ul> {% categoryList allCategories with all=true parentId="0" %} {% for item in allCategories %} <li> {% if item.ModuleId == 1 %} <span class="category-type">[文章]</span> {% elseif item.ModuleId == 2 %} <span class="category-type">[产品]</span> {% endif %} <a href="{{ item.Link }}">{{ item.Title }}</a> </li> {% endfor %} {% endcategoryList %} </ul> </nav>This method is suitable for scenarios where it is necessary to display all categories mixed in a list and can be distinguished on the front end through conditional judgment.Please note that if the amount of data is very large, too many filters within the template may cause a slight impact on the performance of front-end rendering.
Considerations in practice
This design of AnQi CMS actually also encourages us to maintain clarity in template logic: eachcategoryList
Common Questions (FAQ)
- Q: How can I display both the "Company News" category (from the article model) and the "Latest Products" category (from the product model) in a navigation bar?A: You should call `category` twice