Exquisite control of classification list: AnQiCMScategoryListinoffset,limitPractical application of patterns
As an experienced website operations expert, I know how important it is to have flexible data display capabilities when building and optimizing website content. AnQiCMS, with its concise and efficient features, provides us with many powerful template tags, among whichcategoryListTags are the core tools for managing the classification content of a website. Today, let's delve deeper into it.categoryListin the taglimitAn advanced usage of a parameter——the "start position, number" pattern, see how it helps us achieve more refined and dynamic content layout.
Mastering the data stream: understandinglimitParameter's 'start position, number' pattern
We all know,categoryListlabel'slimitThe parameter can be used to control the number of categories we want to retrieve, such aslimit="10"It will fetch the first 10 categories. However, AnQiCMS provides a more operational mode on this basis:limit="起始位置,数量".
This pattern allows us to precisely extract the part we want from the classified data stream, just like 'slicing'. Specifically:
- Starting position (Offset)It refers to the starting point of the category list you want to retrieve. Please note that in the AnQiCMS mode,The starting position is based on index 1.For example, if you want to start from the second category, the starting position is
2. - Quantity (Limit)It indicates starting from the specified position and getting a total of how many category data items you want.
For example,limit="3,5"It means that AnQiCMS will find the 3rd category from your category data, then start counting from it, and extract a total of 5 categories (i.e., the 3rd, 4th, 5th, 6th, and 7th categories).This fine control ability provides us with infinite possibilities for creating diverse content displays.
Practical scenario: Make your website content layout more outstanding.
Mastered起始位置,数量Pattern, we can make full use of its great value in various operational scenarios:
1. Homepage modular layout: Create a personalized content display area
Imagine your website's homepage, it might need a prominent 'Hot Categories' section to display the top 3 categories; followed by a 'Recommended Categories' section below, showcasing the next 5 categories; and further down, a 'Latest Categories' section to display the newest categories.
- Popular category area (first 3):
{% categoryList hotCategories with moduleId="1" parentId="0" limit="3" %} {# 渲染前3个热门分类 #} {% endcategoryList %} - Recommended category area (4th to 8th):
In this way, you can easily split the category list into multiple visually independent blocks, each block displaying different categories, thereby making the home page content richer and the layout more flexible, avoiding the boredom of a single list.{% categoryList featuredCategories with moduleId="1" parentId="0" limit="4,5" %} {# 渲染第4到第8个推荐分类 #} {% endcategoryList %}
2. Pagination and "Load More" optimization: improving user experience
Although AnQiCMS provides a comprehensivetype="page"CombinepaginationTags implement traditional pagination, but in some cases, we may need a more flexible "load more" mechanism, or load specific batches of content on demand without displaying a complete pagination navigation.
- Loaded initially (first 10):
{% categoryList initialLoad with moduleId="1" parentId="0" limit="10" %} {# 首次加载页面时显示前10个分类 #} {% endcategoryList %} - Click 'Load More' for the next 10 (11th to 20th):(This usually requires dynamic modification with JavaScript)
offsetValue)
This pattern makes the "load more" feature logic clearer, and can accurately obtain the next batch of data from the server based on user actions such as scrolling and clicking, providing a smooth browsing experience.{% categoryList nextLoad with moduleId="1" parentId="0" limit="11,10" %} {# 再次点击加载更多时,从第11个分类开始显示10个 #} {% endcategoryList %}
3. Flexible display of sidebars or widgets: precise control of local content
The sidebar, footer, or various widgets on a website often need to display simplified categories