How to help users quickly find the information they are interested in when managing a content-rich website, and improve their access experience, is a challenge that every content operator needs to face. AnQiCMS (AnQiCMS) understands this need and therefore provides powerfularchiveFiltersLabels, allowing you to easily build dynamic filters and provide flexible and diverse search methods for website content.
Dynamic filter, as the name implies, is to automatically generate filter conditions available for users to choose according to different attributes of the content.It is not just a simple classification navigation, but also an intelligent retrieval tool that delves into the details of content.Imagine a real estate website user who wants to filter properties of the type 'Residential' with an area between 90-120 square meters, or a product website user looking for 'Red' T-shirts with a pattern. These complex requirements can be easily addressed through dynamic filters.archiveFiltersLabels are the key to realizing this function.
Building such a filter is not complex.You first need to define various custom fields in the content model of the Anqi CMS backend.For example, for the property model, you can add fields such as 'house type', 'area', 'price range', etc.; for the product model, it can be 'color', 'style', 'material', etc.archiveFiltersLabels can bring out its magic.
UsearchiveFiltersTags usually start like this:{% archiveFilters filters with moduleId=1 allText="全部" %}.
Here,moduleIdThe parameter is very important, it specifies which content model (such as article model, product model, etc.) you want to filter documents for. Different models have different custom fields,moduleIdThe system can accurately retrieve the filtering parameters of the corresponding model.allTextThe parameter allows you to customize the text content of default options such as "Show All" or "Unlimited", even to set it not to display. If your website has enabled the multi-site management feature,siteIdThe parameter can help you specify the data to be retrieved from a specific site.
WhenarchiveFiltersAfter the tag is executed, it will generate a namedfiltersvariable (you can customize this variable name). ThisfiltersA variable is an array object that contains detailed information for each selectable parameter.In the template, you can iterate over these filtered parameters with a loop to dynamically display them on the page.
goes deep intofiltersThe structure of a variable, eachitemrepresents a specific filtering dimension, such as “Type of housing” or “Area”. Eachitemincludes the following key information:
item.Name: This is the display name of the filter, which the user will see on the page, for example, “House Type”.item.FieldName: This is the actual field name defined in the background content model, which is the basis for the system to identify and filter dimensions.item.ItemsThis is the array of all selectable values under the current filter dimension, and it is also an array itself.
Next, we need to.item.ItemsPerform a second loop to display specific options under each filtered dimension, such as 'Residential', 'Commercial', or 'Small apartment', 'Large apartment'. In this loop, eachvalThe object will provide:
val.Label: This is the display text of the filter options, which the user clicks.val.Link: This is a complete URL automatically generated by the Anqi CMS, clicking it will automatically apply the filter condition and refresh the content list.The system will intelligently add the filter conditions in the form of query parameters to the URL.val.IsCurrent: This is a boolean value used to indicate whether the current option has been selected.This is very useful when adding styles (such as highlighting) to the currently selected filter conditions, which can significantly enhance the user interface friendliness.
Combine all this, and we can build a complete and interactive filtering interface in the template. For example, in a list of property documents, you can first usearchiveFiltersTag generation filtering conditions, then combinearchiveListTags (configurationtype="page"and support pagination and URL parameter filtering) andpaginationLabel to display the list of filtered documents and pagination navigation. When the user clicks on a filter option,val.Linkthe page will jump to a URL with the corresponding query parameters,archiveListThe label will automatically recognize these parameters and only display documents that meet the conditions.
Through this method, the Aanqi CMS ofarchiveFiltersThe tag greatly simplifies the development of dynamic filtering functions.It not only improves the organization and discoverability of website content, but also allows users to obtain the necessary information more efficiently and accurately, thereby significantly enhancing the overall user experience.Use this tag flexibly, which will make your website content operation twice as effective.
Common Questions (FAQ)
问:我已经在后台为内容模型添加了自定义字段,但为什么
archiveFilters标签没有显示这些字段作为筛选条件?- Answer:Please check if you have set the custom field you created in the content model to 'filterable'. Only fields that are explicitly marked as filterable are eligible.
archiveFiltersLabel to identify and use it as a dynamic filter condition. In addition, make sure youarchiveFiltersspecified correctly in the labelmoduleIdto associate with the correct custom content model.
- Answer:Please check if you have set the custom field you created in the content model to 'filterable'. Only fields that are explicitly marked as filterable are eligible.
Q:
archiveFiltersgenerated filter link (val.LinkDoes it look like a normal URL with parameters, will it affect my website's SEO?- Answer:
archiveFiltersThe generated links usually contain query parameters (such as?field=valueThis is in many cases what search engines can understand and crawl. For SEO-friendly URLs, Anqi CMS supports pseudo-static rule configuration.archiveFiltersThe generated URLs are parameterized, but you can combine it with the backend's pseudo-static rule management feature for optimization. If there are many filtering conditions resulting in long URLs or duplicate content, consider usingrel="canonical"Label the standard URL of the content to avoid SEO weight dispersion.
- Answer:
Question: Can I use multiple labels on the same page?
archiveFiltersLabel to independently filter different content lists?- Answer:Technically possible, but note the conflict in variable names. If using multiple
archiveFilterslabels, you need to assign different variable names to each label (for examplefilters1/filters2),to avoid overlap.archiveListThe tag also needs to specify the source of its filtering parameters, or ensure thatmoduleId/categoryIdThe correctness of parameters, so that they can respond to their respective filters. In practice, a filter usually serves a main content list.
- Answer:Technically possible, but note the conflict in variable names. If using multiple