How to dynamically filter and display a list of articles through URL parameters or search keywords?

Calendar 👁️ 75

Today, with the increasingly refined content management, how to make your website content smarter and more considerate in serving visitors is the key to improving user experience and website value.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides powerful functions to help us achieve this, especially in dynamic filtering and displaying article lists. The combination of template tags with URL parameters can easily build a highly customizable content presentation style.

This article will provide a detailed introduction on how to use URL parameters and search keywords to dynamically filter and display your article list in AnQi CMS, making your website content more interactive and practical.


Understand the core mechanism of dynamic filtering

In Anqi CMS, dynamic filtering of article lists mainly relies on two core template tags:archiveList(Document list tag) andarchiveFilters(Document parameter filter tags), and combine with the query parameters in the URL.

When a user visits a page in a browser, the URL may contain some parameters starting with “?” such as/?category=技术&q=CMS. Anqi CMS'sarchiveListThe tag is very smart, when it is set to pagination mode (type="page"It automatically recognizes and applies these URL parameters to filter the list of displayed articles.This means that we do not need to write complex backend logic, just by reasonably using tags in the frontend template, we can achieve rich filtering functions.


Based on keyword-based quick search

The most common dynamic filtering method is to search by keywords. Visitors usually hope to quickly find relevant articles by entering keywords.

Implementation method:

  1. Build a search form:Add a simple HTML search form at an appropriate location on the website (such as the navigation bar, sidebar), and the form submission method should be:method}GETand the search box'snameproperty is usually set toq.

    <form method="get" action="/search">
        <div>
            <input type="text" name="q" placeholder="请输入搜索关键词" value="{{urlParams.q}}">
            <button type="submit">搜索</button>
        </div>
    </form>
    
    • Hereaction="/search"points to the search results page template of your website (usuallysearch/index.html)
    • value="{{urlParams.q}}"can retain the keywords entered by the user after searching, improving user experience.
  2. Display search results:In the template of the search results page (or any other page that needs to display search results), usearchiveListlabel and specifytype="page". Anqi CMS will automatically read the URL parameter ofqParameters, and filter the list of article titles containing the keyword based on its value.

    {% archiveList archives with type="page" limit="10" %}
        {% for item in archives %}
        <article>
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description}}</p>
            <footer>发布日期: {{stampToDate(item.CreatedTime, "2006-01-02")}}</footer>
        </article>
        {% endfor %}
        {# 配合分页标签显示分页 #}
        {% pagination pages with show="5" %}
            {# ... 分页链接代码 ... #}
        {% endpagination %}
    {% endarchiveList %}
    

    In this way, when the user submits a search form or directly accesses similaryourdomain.com/search?q=安企CMSURL, thearchiveListIt will automatically display articles matching the keywords.


3. Use built-in fields for filtering.

In addition to keyword search, Anqi CMS also allows you to filter the article list through built-in fields (such as category ID, model ID, recommendation attributes, etc.).

Implementation method:

You can directly control it by adding the corresponding parameters in the URL.archiveListFilter behavior.

  • Filter by category ID: yourdomain.com/list?categoryId=1(Display articles with category ID 1)
  • Filter by model ID: yourdomain.com/list?moduleId=2(Display articles with model ID 2, such as product models)
  • Filter by recommended attributes: yourdomain.com/list?flag=c(Display articles with the recommended attribute 'Recommended')

You can manually build these filter links in the template or automatically generate them with navigation tags. For example, on a category list page, you can generate links with each subcategory havingcategoryIdParameter link:

{% categoryList categories with moduleId="1" parentId="0" %}
    <ul>
        {% for item in categories %}
        <li><a href="{{ item.Link }}">{{item.Title}}</a></li>
        {% endfor %}
    </ul>
{% endcategoryList %}

In the document list page (archiveList type="page"), ifcategoryIdnot specified, it will automatically try to read the category ID of the current page for filtering.


Four, achieve advanced dynamic filtering through custom fields

This is the powerful feature of Anqi CMS dynamic filtering, which allows you to create complex filters based on the article attributes you define (such as region, property type, color, etc).

Implementation steps:

  1. Preparation: Define custom fields in the content modelFirstly, you need to go to the Anqi CMS backendContent Management -> Content ModelIn, add custom fields to the article model you need to filter.For example, if your website is a real estate website, you may need to add fields such as 'Region' (single select/dropdown) and 'House Type' (multiple select) in the article model.When adding fields, you can choose different field types (such as single-line text, numbers, single selection, multiple selection, dropdown selection, etc.), which will be provided for editors to fill in when the article is published.Especially the selection type field (single, multiple, dropdown), their option values will be used directly for filtering.

  2. Build the filtering interface: usearchiveFiltersTagIn your article list page template, usearchiveFiltersThe label is automatically generated based on these custom field options.This tag will read the filter fields defined in your content model and generate links with corresponding URL parameters.

    `twig

    <h4>筛选条件</h4>
    {% archiveFilters filters with moduleId="1" allText="不限" %}
        {% for item in filters %}
        <ul class="filter-group">
            <li><strong>{{item.Name}}:</strong></li> {# 字段名称,如“地区” #}
            {% for val in item.Items %}
    

Related articles

How to embed and display a留言验证码in a front-end form?

In website operation, the message board and comment area are often important channels for interaction with users.However, the garbage information and malicious submissions that follow are also a headache.An effective method of integrating captcha functionality to filter out this noise.Today, let's talk about how to easily embed and display a message captcha in the frontend form of AnQiCMS (AnQiCMS), building a defense line for your website.

2025-11-09

How to convert multi-line text content into HTML format using a newline character?

In content management, we often encounter situations where we need to enter multiline text, such as product details, service introductions, company profiles, or contact information.This content is typically segmented by pressing the Enter key during backend editing.However, when this content is directly presented on the website front end, you may find that it is 'squeezed' together, with all line breaks disappearing, which not only affects the reading experience but also makes the page look disorganized.AnQi CMS as an efficient enterprise-level content management system, of course, has considered this point and provided a variety of elegant solutions

2025-11-09

How to dynamically obtain and display the current year in the template?

In website operation, it is crucial to maintain the timeliness and accuracy of content, especially information like copyright year, which, if manually updated, is not only cumbersome but also prone to omission.Our company AnQi CMS provides a very convenient way to dynamically obtain and display the current year in templates, ensuring the latest information on the website.

2025-11-09

How to display a custom shutdown notice to visitors when the website is under maintenance?

As website operators, we always encounter situations where we need to maintain and upgrade the website, whether it is database optimization, system updates, or content adjustments. These operations sometimes require temporarily shutting down the website to avoid unexpected errors or incomplete content display during maintenance.However, simply displaying a "cannot open" error page on a website undoubtedly gives visitors a bad experience, and may even make search engines mistakenly believe that the website is permanently offline.AnQiCMS (AnQiCMS) fully understands this pain point and provides a graceful and flexible solution that allows you to maintain your website while it is closed for maintenance

2025-11-09

How to manage and display category Banner images and thumbnails?

In website operation, the category page is an important link in guiding users to browse and deepen the brand impression.To configure a unique banner image and thumbnail for the category page, it can not only enhance the visual appeal of the website, but also allow users to intuitively understand the category content, effectively optimizing the user experience.AnQi CMS provides flexible and easy-to-operate functions in this regard, helping us manage and display these visual elements efficiently.

2025-11-09

How to display both subcategories and the list of articles under the category on a category page?

When operating the AnQiCMS website, we often encounter such a need: on a category page, we not only want to display the list of articles under the category but also clearly list all its subcategories to facilitate users in making more detailed navigation.The Anqi CMS, with its flexible template engine and rich built-in tags, can fully help us easily achieve this goal. ### Understanding AnQi CMS Category Page and Template Mechanism In AnQi CMS, each category (whether it is an article category or a product category) can be associated with an independent template file. Generally speaking

2025-11-09

How to correctly display HTML rich text content in article content using the `safe` filter?

In website content operation, rich text content plays a vital role.It allows us to enrich the expression of the article with various formats such as images, links, bold, italic, and more, enhancing the reading experience.AnQiCMS (AnQiCMS) provides a powerful backend editor, making it easy for us to create various wonderful content.However, when this rich text content is finally displayed on a website page, sometimes you may find that the original beautiful formatting and links have become raw HTML code strings. Why is that?

2025-11-09

How to use filters in a template to format displayed numbers and strings (such as decimal places, case conversion)?

In website content presentation, the aesthetics and readability of the data are as important as the quality of the content itself.AnQiCMS (AnQiCMS) provides powerful filter (Filters) functions at the template level, allowing us to easily format numbers and strings displayed on the page, thereby enhancing user experience and the professionalism of page information. ### Filter: A process in data processing We can imagine a filter as a series of processes that handle data.Raw data is like unprocessed raw materials, after the processing of the filter, it can be shaped into what we need

2025-11-09