When operating a website, we often encounter the need to display content. One common scenario is how to precisely control the displayed content on a category list page.Sometimes, we wish to display not only the documents under a main category page, but also the documents under all its subcategories, in order 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 wish to strictly display the documents under the current category, without including any content from subcategories.
Auto CMS is a flexible content management system that fully considers the diversified needs of users and provides a very simple and efficient way to handle this content display logic.
Reveal the core features:archiveListTags andchildParameters
In AnQi CMS, the key to displaying only the current category documents on the category list page without including subcategory documents is to usearchiveListtemplate tags.childParameter.
archiveListLabels are the core tools used by AnQi CMS to retrieve document lists, supporting 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 on the category list pagearchiveListWhen labeling, it will automatically include documents under the current category and all its subcategories. This design can provide rich content display in most cases.
但如果你的目标是精确地只显示当前分类的文档,那么只需在 EnglisharchiveListput in the tagchildparameter settingsfalseThe system will intelligently filter out all sub-category documents after receiving this command, retaining only the content directly associated with the current category.
Below is an example of a category list page usingarchiveListTags, and ensure that only 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,archiveListTagschild="false"The parameter ensures that only the documents under the current visited category (for example, pages with category ID 10) are listed, and the documents under any subcategories of this category (for example, category IDs 11, 12, etc.) are excluded.
It is worth mentioning that in the category list page usagearchiveListusually no additional specification is requiredcategoryIdParameter.Because the AnQi CMS is sufficiently intelligent, it will default to trying to read the current page's category ID to retrieve the document.categoryId="你的分类ID"to achieve.
Why choose precise display? The considerations behind it
Using this strategy that only displays the current category documents can bring multiple benefits:
- Enhancing 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 content from subcategories is included, it may confuse users and reduce search efficiency.The precise display makes the page theme clearer, allowing users to find the information they need at a glance.
- Optimizing SEO effects:For search engines, the concentration and relevance of page content are important considerations in the ranking algorithm.An English page that only contains documents of the current category, with 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 relevant search results.
- Simplifying content management logic:For website operators, precise control of content display can make the content structure clearer, convenient for daily content publishing, maintenance, and data analysis.
- Avoid content repetition and dilution: In some complex classification systems, if the content of the subcategory is also displayed on the parent category page, it may lead to a large amount of repeated content display, diluting the unique value of each page.
MorearchiveListParameter Combination Suggestions
In the settingschild="false"On this basis, you can also combine otherarchiveListparameters to further refine your content display:
moduleId="1"(Model ID):If your website has multiple content models (such as articles, products), you canmoduleIdspecify parameters to only display documents under a specific model.order="id desc"(Sort method):Control the sorting of the document, for example, by the most recent release (id desc), most viewed (views desc) or custom sorting (sort desc).limit="10"(Display Quantity):Control the number of documents displayed per page.flag="c"(Recommended Property):Only display documents with specific recommended properties (such as recommended [c], headlines [h], etc.).
Through the flexible application of these parameters, you can build highly customized, powerful category list pages in the CMS, whether for enhancing user experience, optimizing SEO, or simplifying content management, you can do it with ease.
Common Questions (FAQ)
1. This setting (child="false") will affect other category pages on my website?No.child="false"parameters only affect the modification you madearchiveListThe specific category list page template for tags is effective.If you do not add or modify this parameter in the template of other category list pages, they will continue to follow the original content display logic (usually including subcategory documents by default).
2. I want to display documents of the current category and a specific subcategory at the same time, but exclude other subcategories. Is it possible?Yes. In this case, you can avoid usingchild="false"Parameters. Instead, it directly incategoryIdParameters, enter the category ID you want to include, 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 there is no category list page template at allarchiveListwhat should I do?if there is no category list page templatearchiveListThe label indicates that the current page may not be properly configured for displaying the document list. You need to manually add it in the template.archiveListLabel. First determine which content model you want to display (for example, article model ID is 1), and then configure it according to the above example, at least includingmoduleIdandtypeParameter, for example: {% archiveList archives with moduleId="1" type="page" limit="10" child="false" %}Of course, if you need pagination, remember to addpaginationLabel.