Today, as content management is increasingly becoming the core competitiveness of corporate websites, AnQiCMS (AnQi Content Management System) helps us easily manage massive amounts of content with its flexible and efficient features.When you need to precisely filter and display a list of documents with specific titles, categories, or attributes, AnQiCMS provides intuitive and powerful template tags to make this process simple and efficient.
core tools:archiveListTag Overview
To display document lists on the website frontend, we mainly use the core template tags of AnQiCMSarchiveListThis tag is powerful, it can filter content based on various conditions and display it in a list or paginated form. It supports multiple parameters, allowing you to finely control the presentation of content.
通常,您会看到这样的基本结构来调用文档列表:
{% archiveList archives with type="list" limit="10" %}
{% for item in archives %}
{# 在这里展示每个文档的详细信息 #}
{% empty %}
<p>该列表没有任何内容。</p>
{% endfor %}
{% endarchiveList %}
In this code,archives是我们为文档列表指定的一个变量名,您可以根据自己的喜好来命名。forThe loop will iterate over each document in the list (we call ititem), and display its content within the loop. If the list is empty,emptythe content within the tags will be displayed.
Based on category and content model filtering
Flexible content model design of AnQi CMS allows us to create independent models for different types of content (such as articles, products, events, etc.) and establish a classification system for each model. When you need to filter documents under a specific category,archiveListTagscategoryIdandmoduleIdThe parameters become particularly important.
Filter by content model (
moduleId): If you want to display all documents under the "Article Model" and ignore the content of the "Product Model", you can setmoduleId="1"(Assuming the article model ID is 1). This is very useful for distinguishing content across different models.Filter by category (
categoryId)When you need to display documents under a specific category, just provide the ID of that category. For example,categoryId="10"The document under the category with ID 10 will be displayed. If you want to display the content of multiple categories at the same time, you can pass multiple IDs separated by commas, for examplecategoryId="10,12,15".Exclude specific categories ()
excludeCategoryId)Alternatively, if you want to display all documents under a model except for specific categories, you can useexcludeCategoryId="10"to exclude categories with ID 10.Include subcategories (
child): By default, when you specify a category ID,archiveListIt will automatically include all documents under its subcategories. If you only want to display documents of the current specified category itself and not include its subcategories, you canchildparameter settingsfalse, which ischild=false.
Filter content based on document attributes
In addition to classification, AnQiCMS also allows you to set various "recommended properties" (Flag) for documents, which are like special tags attached to documents, such as "headlines", "recommended", "sliders", etc. UtilizingflagParameters, you can easily filter out documents with specific properties:
Specify recommended properties ()
flag)For example, to filter out all documents marked as "Top News", you can useflag="h"。The document supports the following attribute values:h(Headlines),c(Recommended),f(Slideshow),a(Special Recommendation),s(滚动)、p(图片)、j(跳转)。You can combine them flexibly according to your needs.Exclude recommended attributes (
excludeFlag): If you do not want to display certain properties of documents in the list, you can useexcludeFlagparameters, such asexcludeFlag="s"Exclude all documents marked as 'scrolling'.Specify an author or parent document (
userId,parentId)For websites with multiple authors or documents in a hierarchy (such as sub-documents), you can also use the following methods touserIdorparentIdParameters can be used to filter documents published by specific authors, or the sub-content of specific superior documents.
Implement keyword search and advanced dynamic filtering.
In many scenarios, visitors need to search for content by entering keywords or filter based on multiple custom conditions.
Keyword search (
q)When you need to create a search results page,archiveListTagsqthe parameters are very useful. Usually, we will use list typetypesetpageso that the keywords entered by the user in the search box (via the parameters in the URL) will be automatically translated into EnglishqarchiveListCapture and use for search. For example, after a search form is submitted, the URL may be/search?q=安企CMSin your template.archiveListIt will automatically filter based on "Anqi CMS".Advanced Dynamic Filtering (
archiveFilters)Imagine a real estate website, where users may need to filter listings based on multiple conditions such as “Property Type”, “Area”, “Price Range”, and more. At this point,archiveFiltersLabels can be put to use. It will automatically generate a series of filtering conditions and their corresponding links based on the custom fields you configure for the content model in the background. You just need to.archiveFiltersTags andarchiveListLabels (set astype="page"Combine usage, providing users with a powerful dynamic filtering experience.In the template, you can use it like this:
archiveFilters:{% archiveFilters filters with moduleId="1" allText="不限" %} {% for item in filters %} <ul> <li>{{ item.Name }}: </li> {% for val in item.Items %} <li class="{% if val.IsCurrent %}active{% endif %}"><a href="{{ val.Link }}">{{ val.Label }}</a></li> {% endfor %} </ul> {% endfor %} {% endarchiveFilters %}This code will cyclically display all filterable parameters (such as “Type of housing”) and the specific options under each parameter (such as “Residential”,”Commercial”). When the user clicks on an option, the page URL will automatically include the corresponding filter parameters and by
archiveListLabel capture and apply.
Content display and pagination control.
After filtering out the appropriate documents, how to beautifully display them and provide a friendly pagination experience is equally important.
Traverse and display detailed content: In
archiveListofforin the loop,itemThe variable represents the document currently being processed. You canitem.TitleGet the document title,item.LinkGet the document link,item.DescriptionGet the document summary,item.ThumbGet the document thumbnail, etc. For time, you can{{ stampToDate(item.CreatedTime, "2006-01-02") }}Format the display. If the document summary or content contains HTML tags, remember to add|safea filter to avoid escaping.For example: “`twig {% for item in archives %}
<h2><a href="{{ item.Link }}">{{ item.Title }}</a></h2> {% if item.Thumb %} <img src="{{ item.Thumb }}" alt="{{ item.Title }}"> {% endif %} <p>{{ item.Description|safe }}</p> <footer> <span>发布日期:{{ stampToDate(item.CreatedTime, "2006年01月02日") }}</span> <span>浏览量:{{ item.Views }}</span> {% if item.CategoryId %} <span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span> {% endif %} </footer>