Today, as content management is increasingly becoming a core competitive force for corporate websites, AnQiCMS (AnQiCMS) helps us easily handle massive amounts of content with its flexible and efficient features.When you need to accurately 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 tool:archiveListTag Overview
To display the document list on the website front-end, we mainly use the core template tags of AnQiCMSarchiveList. This tag is powerful, able to filter content based on various conditions and display it in a list or paginated form. It supports multiple parameters to finely control the presentation of content.
usually, you will see such a basic structure to call the document list:
{% archiveList archives with type="list" limit="10" %}
{% for item in archives %}
{# 在这里展示每个文档的详细信息 #}
{% empty %}
<p>该列表没有任何内容。</p>
{% endfor %}
{% endarchiveList %}
In this code block,archivesis the variable name we specify for the document list, you can name it according to your preference.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 AnQiCMS, allowing 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,archiveListlabel'scategoryIdandmoduleIdParameters are 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 models when displaying.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 documents 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 a specific category (
excludeCategoryId) Conversely, if you want to display all documents under a model except for a specific category, you can useexcludeCategoryId="10"to exclude category with ID 10.Containing subcategory (
child)By default, when you specify a category ID,archiveListIt will automatically include all documents under its subcategories. If you only want to display the documents of the current specified category without including its subcategories, you canchildthe parameter tofalse, that ischild=false.
Filter documents based on document attributes
In addition to categories, AnQiCMS also allows you to set various 'recommended properties' (Flag) for documents, which are like putting special tags on documents, such as 'headlines', 'recommended', 'slides', etc. UsingflagParameters, you can easily filter out documents with specific properties:
Specify recommended attributes (
flag): For example, to filter out all documents marked as "Top News", you can useflag="h". The document supports the following attribute values:h(Headline),c(Recommended),f(Slide),a(Special recommendation),s(Scrolling)、“p(Image)、“j(Jumping) Please flexibly combine according to your needs。“Exclude recommended attributes (
excludeFlag)If you do not want certain attributes of documents to be displayed in the list, you can useexcludeFlagparameters, for exampleexcludeFlag="s"Documents marked as "scrolling" will be excluded.Specify the author or parent document (
userId,parentId): For multi-author websites or documents with hierarchical relationships (such as subordinate documents), you can also filter specific author's published documents or the sub-content of specific superior documents byuserIdorparentIdparameters.
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,archiveListlabel'sqthe parameters are very useful. Usually, we will list the typetypeis set topagesuch that the keywords entered by the user in the search box (via the URL parameters) will be automaticallyqtransmittedarchiveListCapture 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 might need to filter listings based on multiple conditions such as "house type", "area", "price range", and so on. 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. You just need toarchiveFilterswith the tag andarchiveListTag (set as)type="page"Use them together to provide 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 loop through all the filterable parameters (such as "house type") 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 also important.
Details of traversal and display contentIn
archiveListofforthe loop,itemThe variable represents the current document being processed. You canitem.TitleGet the document title,item.LinkGet the document link,item.DescriptionGet the document summary,item.ThumbRetrieve document thumbnails and the like. For time, you can use{{ stampToDate(item.CreatedTime, "2006-01-02") }}to 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>