When operating a website, we often encounter the need to display content, one common scenario is how to accurately control the display content on the category list page.Sometimes, we hope to display not only the documents under a main category page but also the documents under all its subcategories to provide more comprehensive information.However, in some cases, in order to maintain the purity of the page theme and the focus of the content, we may only want to strictly display the documents under the current category and not include any content from subcategories.

AnQi CMS is a flexible content management system that fully considers the diverse needs of users and provides a very simple and efficient way to handle this content display logic.

The core feature revelation:archiveListwith the tag andchildParameter

The key to displaying only the current category documents in the category list page of AnQi CMS without including subcategory documents is to usearchiveListtemplate tagschildParameter.

archiveListThe tag is the core tool of Anqi CMS used to retrieve document lists, it supports various parameters to filter, sort, and control the display of documents. Among them,childThe parameter is used to control whether to include subcategory documents.

By default,childThe value of the parameter istrueThis means that when you call the category list page,archiveListWhen a tag is used, it automatically includes the documents under the current category and all its subcategories. This design provides rich content display in most cases.

But if your goal is to precisely display only the current category of documents, then just inarchiveListput in the tag.childthe parameter tofalse. The system will intelligently filter out all documents of subcategories after receiving this command, retaining only the content directly associated with the current category.

Below is an example of using in the category list page.archiveListLabel, and ensure that only the simplified examples of the current category documents are displayed:

{# 假设这是你的分类列表页模板,例如 /template/default/article/list.html 或 /template/default/article/list-123.html #}

<div class="category-document-list">
    {% archiveList archives with type="page" limit="10" child="false" %}
        {% for item in archives %}
        <div class="document-item">
            <a href="{{item.Link}}" title="{{item.Title}}">
                <h3>{{item.Title}}</h3>
                <p>{{item.Description|truncatechars:100}}</p>
                <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                <span>浏览量:{{item.Views}}</span>
            </a>
        </div>
        {% empty %}
        <p>当前分类下暂无文档。</p>
        {% endfor %}
    {% endarchiveList %}

    {# 如果需要分页,可以结合 pagination 标签使用 #}
    {% pagination pages with show="5" %}
        {# 分页导航的代码,根据你的模板设计进行编写 #}
        {% if pages.TotalPages > 1 %}
            <div class="pagination-nav">
                <a href="{{pages.FirstPage.Link}}" class="{% if pages.FirstPage.IsCurrent %}active{% endif %}">{{pages.FirstPage.Name}}</a>
                {% if pages.PrevPage %}<a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a>{% endif %}
                {% for p in pages.Pages %}<a href="{{p.Link}}" class="{% if p.IsCurrent %}active{% endif %}">{{p.Name}}</a>{% endfor %}
                {% if pages.NextPage %}<a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a>{% endif %}
                <a href="{{pages.LastPage.Link}}" class="{% if pages.LastPage.IsCurrent %}active{% endif %}">{{pages.LastPage.Name}}</a>
            </div>
        {% endif %}
    {% endpagination %}
</div>

In this example,archiveListlabel'schild="false"The parameter ensures that only documents under the current category (such as, pages with category ID 10) are listed, while documents under any subcategory (such as, category IDs 11, 12, etc.) of the category are excluded.

It is worth mentioning that it is usually not necessary to specify extra when using it in the category list pagearchiveListwhencategoryIdParameter. Because AnQi CMS is smart enough, it will try to read the category ID of the current page by default to get the document.Of course, if you need to use it on other pages or want to specify a category ID more explicitly, you can also do socategoryId="你的分类ID"to achieve.

Why choose precise display? The considerations behind it

Adopting this strategy of displaying only the current category documents can bring various benefits:

  1. Enhance user experience and navigation clarity:When the user clicks on a category, they expect to see documents directly related to the theme of that category.If mixed with the content of subcategories, it may confuse users and reduce search efficiency.The precise display can make the page theme more clear, allowing users to find the information they need at a glance.
  2. Optimize SEO effect:For search engines, the concentration and relevance of page content are important factors in the ranking algorithm.A page that only contains documents of the current category, with a higher keyword density and thematic focus, which helps search engines better understand the content of the page, thereby improving the ranking of the category page in related search results.
  3. Simplify content management logic:For website operators, precise control over content display can make the content structure clearer, convenient for daily content publication, maintenance, and data analysis.
  4. Avoid content repetition and dilution:Under certain complex classification systems, if the content of the sub-classification is also displayed on the parent classification page, it may lead to a large amount of repeated content display, diluting the unique value of each page.

MorearchiveListParameter Matching Suggestions

In the settingchild="false"On this basis, you can also combine otherarchiveListParameters, further refine your content display:

  • moduleId="1"(Model ID):If your website has multiple content models (such as articles, products), you canmoduleIdspecify parameters to display documents under specific models only.
  • order="id desc"(Sorting method):Control the document sorting, such as by most recent release (id desc), most viewed (views desc), or custom sorting (sort desc)
  • limit="10"(display count):Control the number of documents displayed per page.
  • flag="c"(Recommended Attribute):Only display documents with specific recommended attributes (such as recommended[c], headline[h], etc.).

By flexibly using these parameters, you can build highly customized and powerful category list pages in Anqi CMS, whether it is to enhance user experience, optimize SEO, or simplify content management, you can handle it with ease.


Frequently Asked Questions (FAQ)

1. This setting (child="false") will affect other category pages on my website?No.child="false"The parameter only modifies your settingsarchiveListThe specific category list page template takes effect. If you do not add or modify this parameter in the template of other category list pages, they will continue to use the original content display logic (usually including subcategory documents by default).

2. Can I display documents from the current category and a specific subcategory at the same time, excluding other subcategories, is this possible?Yes. In this case, you can omitchild="false"Parameters. Instead, it is directly incategoryIdEnter the category ID you want to include in the parameter, including the current category ID and the specific subcategory ID you want to display, separated by English commas,For example: {% archiveList archives with categoryId="1,2,5" type="page" limit="10" %}.

3. If my category list page template does not havearchiveListWhat should I do with the tags?If your category list page template does not havearchiveListLabel, that means that the current page may not be properly configured to display the document list. You need to manually add it in the templatearchiveListLabel. First determine which content model you want to display (for example, the article model ID is 1), then configure it according to the above example, at least includingmoduleIdandtypefor example:{% archiveList archives with moduleId="1" type="page" limit="10" child="false" %}Of course, if you need pagination, remember to addpagination.