As an experienced website operation expert, I have a deep understanding of the powerful functions and flexible template system of AnQiCMS (AnQiCMS).In daily content operation, we often encounter the need to aggregate and display different types of content.Today, let's delve into it in depthcategoryListin the tagmoduleIdThe use of parameters, especially whether it can specify multiple model IDs for joint queries at the same time.
Deep understandingcategoryListwith the tag andmoduleIdParameter
in the AnQi CMS template world,categoryListLabels are undoubtedly one of the core tools for content aggregation and display.It allows us to conveniently obtain and display the classification structure of the website, whether it is article classification, product classification, or other customized content model classifications, they can be flexibly retrieved through it.moduleIdThe parameter is exactlycategoryListThe core of the label, which is mainly used to specify which content model's category list you want to get.
One of the highlights of AnQi CMS is its flexible content model design.This means you can create various content types based on business needs, such as an "article model" for publishing news blogs, a "product model" for displaying 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: “I need to retrieve the article model (“moduleId=1All categories under or "The product model I need is ("moduleId=2Categories under ("
moduleIdCan the parameter achieve multi-model joint query?
Now, let's face the core issue:categoryListlabel'smoduleIdCan the parameter specify multiple model IDs at the same time, for example?moduleId="1,2"ormoduleId="1|2"Thus, can we achieve joint queries or mixed displays of different content model classifications?
Based on a deep understanding of the AnQi CMS features and template tag syntax, my answer is:categoryListlabel'smoduleIdParameterCannot directly use multiple model IDs (for example, separated by commas or pipes) to perform a union query across different model categories.
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 parameter is intended to explicitly specify the classification under "which" content model, rather than "which" models. The document mentionedmoduleId="1|2|3"It is more like an illustrative expression of the parameter "possible values", hinting that it can accept model ID 1, 2 or 3, but does not indicate that these three IDs can be input simultaneously for a joint query. In actual template parsing,moduleIdExpect a single integer value representing a specific content model ID.
How to implement an aggregated display of multi-model classification?
AlthoughmoduleIdThe parameter itself does not support joint queries of multiple models, but this does not mean that we cannot flexibly aggregate and display data from different models in the template. Anqi CMS provides enough flexibility to meet such needs, and there are mainly the following strategies:
Call in stages
categoryListTagThis is the most direct and clearest implementation. If you need to display categories from different models in different areas of the page or according to different logic, you can use it multiple times.categoryListLabel, passed in each callmoduleId.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 to maintain, each group of classification data comes from its respective model, and the responsibilities are clear.
Utilize
all=trueParameters retrieve all categories and perform template-level filtering.: If you need to getallall categories under the content model (not limited to a specific model),categoryListprovided a more direct parameter:all=true. When you useall=truethen,categoryListwill ignoremoduleIdparameter (if specified)moduleId, thenall=trueIt will only retrieve all categories under the specified model, not all models. You can do this through the template.item.ModuleIdProperties further classify or filter 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 through conditional judgment on the front end.Please note that if the amount of data is very large, too many template filters may cause a slight impact on the front-end rendering performance.
Considerations in practice
The design of AnQi CMS actually encourages us to keep the template logic clear: eachcategoryListCalls are all targeted at a clear content model, making the intention of data acquisition more intuitive and convenient for subsequent maintenance and debugging.When your content structure becomes complex, this clarity greatly reduces the probability of errors.
Frequently Asked 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