Classification list tags

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 IDmoduleId
    moduleIdYou can get a list of classifications for the specified document model, such asmoduleId="1"Get a list of categories for article models.
  • Advanced classificationparentId
    parentIdRepresents 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 classesall
    allYou can get a list of all categories, such asall=trueGet all categories if specified at the same timemoduleId, then get all categories under the specified model.
  • Display quantitylimit
    limitYou can specify the number of displays, for examplelimit="10"Only 10 items will be displayed.limitsupportoffsetMode, that is,Separation mode, if you want to get 10 pieces of data from item 2, you can set it tolimit="2,10".
  • Site IDsiteId
    siteIdGenerally, 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 itsiteIdTo 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 usedforLoop to output

item is a variable in the for loop body. The available fields are:

  • Classification IDId
  • Classification titleTitle
  • Category LinksLink
  • Classification DescriptionDescription
  • Classified contentContent
  • Superior Class IDParentId
  • Classified thumbnailsLogo
  • Classification thumbnailsThumb
  • Sub-level classification prefixSpacer
  • Is there a lower-level classificationHasChildren
  • Is the current linkIsCurrent
  • Number of documents classifiedArchiveCount

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

  1. 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 %}
  1. 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>