Description: Used to obtain articles and product categories lists
How to use:{% categoryList 变量名称 with moduleId="1|2|3" parentId="0" %}
If you define a variable as categories{% categoryList categories with moduleId="1" parentId="0" %}...{% endcategoryList %}
The supported parameters of categoryList are:
- Model ID
moduleId
moduleId
You can get a list of classifications for the specified document model, such asmoduleId="1"
Get a list of categories for article models. - Advanced classification
parentId
parentId
Represents the superior classification, and you can obtain the subcategory under the specified superior classification.parentId="parent"
It means that the superior classification is the superior classification of the current classification, and it means that the brother classification of the current classification is obtained. When parentId="0", get the top-level classification. When you want to get the top-level classification, you must specify the model IDmoduleId
- Get all classes
all
all
You can get a list of all categories, such asall=true
Get all categories if specified at the same timemoduleId
, then get all categories under the specified model. - Display quantity
limit
limit
You can specify the number of displays, for examplelimit="10"
Only 10 items will be displayed.limit
supportoffset
Mode, that is,
Separation mode, if you want to get 10 pieces of data from item 2, you can set it tolimit="2,10"
. - Site ID
siteId
siteId
Generally, there is no need to fill in it. If you use the background multi-site management to create multiple sites and want to call data from other sites, you can specify itsiteId
To implement the data calling the specified site.
If you want to get the following classification of the current classification, you do not need to specify itparentId
. If you want to get the sibling classification of the current category, specifyparentId="parent"
, only valid when it is on the document list.
categories are array objects, so they need to be usedfor
Loop to output
item is a variable in the for loop body. The available fields are:
- Classification ID
Id
- Classification title
Title
- Category Links
Link
- Classification Description
Description
- Classified content
Content
- Superior Class ID
ParentId
- Classified thumbnails
Logo
- Classification thumbnails
Thumb
- Sub-level classification prefix
Spacer
- Is there a lower-level classification
HasChildren
- Is the current link
IsCurrent
- Number of documents classified
ArchiveCount
Code Example
{% categoryList categories with moduleId="1" parentId="0" %} <ul> {% for item in categories %} <li>
{# 如需判断当前是否是循环中的第一条,可以这么写: #} {% if forloop.Counter == 1 %}这是第一条{% endif %} {# 比如需要给第一条添加额外class="active",可以这么写: #} <a class="{% if forloop.Counter == 1 %}active{% endif %}" href="{{item.Link}}">{{item.Title}}</a>
<a href="{{ item.Link }}">{{item.Spacer|safe}}{{item.Title}}</a> <a href="{{ item.Link }}"> <span>当前第{{ forloop.Counter }}个,剩余{{ forloop.Revcounter}}ge</span> <span>分类ID:{{item.Id}}</span> <span>分类名称:{{item.Title}}</span> <span>分类链接:{{item.Link}}</span> <span>分类描述:{{item.Description}}</span> <span>分类内容:{{item.Content|safe}}</span> <span>上级分类ID:{{item.ParentId}}</span> <span>下级分类前缀:{{item.Spacer|safe}}</span> <span>是否有下级分类:{{item.HasChildren}}</span> </a> <div>缩略图大图:<img style="width: 200px" src="{{item.Logo}}" alt="{{item.Title}}" /></div> <div>缩略图:<img style="width: 200px" src="{{item.Thumb}}" alt="{{item.Title}}" /></div> </li> {% endfor %} </ul> {% endcategoryList %}
Multi-level classification nested calls
{% categoryList categories with moduleId="1" parentId="0" %}
{#一级分类#}
<ul>
{% for item in categories %}
<li>
<a href="{{ item.Link }}">{{item.Title}}</a>
<div>
{% categoryList subCategories with parentId=item.Id %}
{#二级分类#}
<ul>
{% for inner1 in subCategories %}
<li>
<a href="{{ inner1.Link }}">{{inner1.Title}}</a>
<div>
{% categoryList subCategories2 with parentId=inner1.Id %}
{#三级分类#}
<ul>
{% for inner2 in subCategories2 %}
<li>
<a href="{{ inner2.Link }}">{{inner2.Title}}</a>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
</div>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
</div>
</li>
{% endfor %}
</ul>
{% endcategoryList %}
Common usage examples
- Display documents under the category in a loop. As shown in the picture:
Call code example (the code does not contain css style control)
{% categoryList categories with moduleId="1" parentId="0" %}
<div>
{% for item in categories %}
<div>
<h3><a href="{{ item.Link }}">{{item.Title}}</a></h3>
<ul>
{% archiveList archives with type="list" categoryId=item.Id limit="6" %}
{% for archive in archives %}
<li>
<a href="{{archive.Link}}">
<h5>{{archive.Title}}</h5>
<div>{{archive.Description}}</div>
<div>
<span>{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
<span>{{archive.Views}} 阅读</span>
</div>
</a>
{% if archive.Thumb %}
<a href="{{archive.Link}}">
<img alt="{{archive.Title}}" src="{{archive.Thumb}}">
</a>
{% endif %}
</li>
{% empty %}
<li>
该列表没有任何内容
</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
{% endfor %}
</div>
{% endcategoryList %}
- Displays the lower-level classification of the classification in a loop multiple categories, and if there is no lower-level classification, the document of the classification is displayed. As shown in the picture:
Call code example (the code does not contain css style control)
<div>
{% categoryList productCategories with moduleId="2" parentId="0" %}
{% for item in productCategories %}
<a href="{{item.Link}}">{{item.Title}}</a>
<ul class="ind-pro-nav-ul">
{% if item.HasChildren %}
{% categoryList subCategories with parentId=item.Id %}
{% for inner in subCategories %}
<li><a href="{{inner.Link}}" title="">{{inner.Title}}</a></li>
{% endfor %}
{% endcategoryList %}
{% else %}
{% archiveList products with type="list" categoryId=item.Id limit="8" %}
{% for inner in products %}
<li><a href="{{inner.Link}}" title="">{{inner.Title}}</a></li>
{% endfor %}
{% endarchiveList %}
{% endif %}
</ul>
{% endfor %}
{% endcategoryList %}
</div>