How to filter and sort articles by category ID and recommendation attributes when displaying the article list in AnQiCMS?

Calendar 👁️ 70

How to effectively organize and present an article list in a content management system is a key factor that directly affects user experience and website information architecture.AnQiCMS provides a flexible and powerful template tag system, allowing us to finely filter and sort articles based on category ID and recommendation attributes, thereby achieving precise content placement and optimized display.

Understand the article list tagsarchiveList

The display of AnQiCMS article list depends onarchiveListThis template tag. It is like a universal content query, which can filter out the content we want to display according to various parameters from a massive amount of articles.No matter whether it is the hot recommendation on the homepage or the latest information under a specific category,archiveListCan easily handle.

When in use, we usually assign the query results to a variable, such asarchivesThen proceedforLoop through these articles to display them. A basic call might look like this:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        <a href="{{item.Link}}">{{item.Title}}</a>
        {# 更多文章详情,如简介、发布时间等 #}
    {% endfor %}
{% endarchiveList %}

Heretype="list"means to get a fixed number of lists,limit="10"The number of displayed articles is limited.

Precise filtering based on category ID

Website content is usually categorized by different themes, and AnQiCMS allows us to filter articles based on these categories. This is done throughcategoryIdParameter to achieve.

  1. specifying a single category: If you only want to display articles under a specific category, just pass the category ID to thecategoryIdparameter. For example, to display articles under the category with ID5‘Company News’ category:

    {% archiveList articlesByCategory with categoryId="5" limit="5" %}
        {% for article in articlesByCategory %}
            <h3><a href="{{article.Link}}">{{article.Title}}</a></h3>
            <p>{{article.Description}}</p>
        {% endfor %}
    {% endarchiveList %}
    
  2. Display multiple categories at the same time: If you need to retrieve articles from multiple non-connected categories, you can use English comma,Connect multiple category IDs:

    {% archiveList mixedArticles with categoryId="1,3,7" limit="10" %}
        {% for article in mixedArticles %}
            <h4><a href="{{article.Link}}">{{article.Title}}</a></h4>
        {% endfor %}
    {% endarchiveList %}
    
  3. Include or exclude subcategoriesBy default, if you do not specify in a category pagecategoryId,archiveListit will try to automatically read the category ID of the current page and display all articles under it, including articles under its subcategories.

    • If you want to display only the current category articles and not include any subcategories, you can explicitly setchild="false":
      
      {% archiveList currentCategoryArticles with child="false" limit="8" %}
          {# 仅显示当前分类下的文章 #}
      {% endarchiveList %}
      
    • If you need to exclude certain categories of articles, you can useexcludeCategoryIdparameters:
      
      {% archiveList allButExcluded with excludeCategoryId="2,4" limit="10" %}
          {# 显示除分类ID 2和4之外的所有文章 #}
      {% endarchiveList %}
      
    • If you do not wisharchiveListAutomatically read the category ID of the current page and want to display all site articles (or not filter by category on other pages), you can setcategoryId="0".

Optimize content exposure by using recommendation attributes

In website operation, we often need to process some special articles with "recommendation", "top" or "slideshow" etc. to increase their exposure. AnQiCMS provides the "recommendation attribute" (flag) To manage these special states.

When editing articles in the background, we can select one or more recommended properties for the article, such as "Headline", "Recommended", "Slideshow", and so on. In the template, throughflagParameters, we can accurately call articles with these attributes.

The recommended attributes supported by AnQiCMS and their corresponding letters are as follows:

  • h: Headline article
  • c: Recommended article
  • f: Slideshow Article
  • a: Featured Article
  • s: Scrolling Article
  • p: Image Article
  • j: Jump Article (usually used for external links, but can also be used for internal special markers)

It should be noted that,flagParameters can only be specified once for filtering recommendations. If you want to display specific recommended articles, such as the 'Recommended' articles on the homepage:

{% archiveList recommendedArticles with flag="c" limit="4" %}
    {% for article in recommendedArticles %}
        <div class="card">
            <h4><a href="{{article.Link}}">{{article.Title}}</a></h4>
            <p>{{article.Description|truncatechars:100}}</p>
        </div>
    {% endfor %}
{% endarchiveList %}

Similarly, if you want to exclude articles with certain recommended properties, you can useexcludeFlagthe parameter. AndshowFlag="true"You can directly display the recommended attributes of the article in the article list (for example, showing a "Recommended" word next to the title).

A flexible sorting mechanism to make the content more orderly.

The presentation order directly affects the efficiency of users in obtaining information. AnQiCMS provides various sorting methods, throughorderparameters to control:

  • order="id desc": Arranged in descending order by article ID, usually used to display the most recently published articles.descMeans descending,ascMeans ascending.
  • order="views desc": Arrange articles in descending order of views, used to display the most popular or most concerned articles.
  • order="sort desc"This is the default custom sorting method of AnQiCMS admin panel.The operation personnel can manually adjust the priority of articles in the background, the higher the number, the higher the sorting.If you want the articles to be displayed in the order set by the background, this parameter is very useful.

For example, to display the latest 5 articles:

{% archiveList latestArticles with order="id desc" limit="5" %}
    {% for article in latestArticles %}
        <li><a href="{{article.Link}}">{{article.Title}}</a> (发布时间: {{stampToDate(article.CreatedTime, "2006-01-02")}})</li>
    {% endfor %}
{% endarchiveList %}

Display the top 3 most popular articles:

{% archiveList hotArticles with order="views desc" limit="3" %}
    {% for article in hotArticles %}
        <p><a href="{{article.Link}}">{{article.Title}}</a> (浏览量: {{article.Views}})</p>
    {% endfor %}
{% endarchiveList %}

Apply comprehensively: Build a smarter article list

The strength of AnQiCMS lies in the flexibility of these parameters, which can help us build article lists that meet various needs. For example, we want to be in the "Product Dynamics" category (assuming the ID is10Under, display all "recommended" (cProduct news of the attribute, sorted by views from high to low, limited to display 6 items:

{% archiveList productNews with categoryId="10" flag="c" order="views desc" limit="6" %}
    {% for item in productNews %}
        <div class="news-item">
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>发布于:{{stampToDate(item.CreatedTime, "2006-01-02")}} | 浏览:{{item.Views}}</p>
            <p>{{item.Description|truncatechars:120}}</p>
        </div>
    {% else %}
        <p>当前分类下没有推荐的产品动态。</p>
    {% endfor %}
{% endarchiveList %}

Such a combination of use allows us to dynamically adjust the way content is presented according to the actual operation strategy of the website, whether it is for SEO, users

Related articles

How does AnQiCMS manage and display single-page content, such as 'About Us' or 'Contact Us'?

In website operation, we often need to create some fixed content, large information independent pages, such as "About Us", "Contact Us", "Terms of Service" or "Privacy Policy" and so on.These pages are usually called single-page content, they are an indispensable part of the website, used to provide visitors with core information, build trust, or guide operations.AnQiCMS provides an intuitive and flexible solution for managing and displaying this type of single-page content.

2025-11-07

How to correctly display Markdown formatted mathematical formulas and flowcharts in AnQiCMS?

For users who often need to publish technical articles, tutorials, or academic content, the Markdown editor is undoubtedly a tool that improves efficiency.Its concise syntax makes content creation intuitive and quick. AnQiCMS, as a modern content management system, naturally takes full consideration of the use scenarios of Markdown and provides strong support.However, when we need to insert complex mathematical formulas or draw intuitive flowcharts in Markdown-formatted articles, relying solely on the features of Markdown itself is not enough. At this point

2025-11-07

How to implement custom display templates for category pages in AnQiCMS?

AnQiCMS provides excellent flexibility in website content management, especially when dealing with category page displays. It is not limited to a single fixed layout but allows users to set personalized display templates for category pages based on different business needs and design concepts.This is undoubtedly a very practical feature for operators who hope to improve user experience, strengthen brand image, or optimize specific SEO strategies through differentiated content display.How is it specifically implemented to customize the display template of the category page in AnQiCMS?

2025-11-07

How to call and display the title, content, and related fields of a document on the AnQiCMS article detail page?

In AnQiCMS, the content detail page is the key area where you display core information and attract readers.Effectively call and display the title, content, and various related fields of the document, which can greatly enhance user experience and the richness of page information.The powerful template engine of AnQiCMS provides an intuitive and flexible way to achieve these goals.## Understanding AnQiCMS Template Syntax AnQiCMS's template system uses syntax similar to Django template engine, it mainly operates data and logic through two forms: * **Double Curly Braces

2025-11-07

How to implement nested list display of multi-level categories in AnQiCMS templates?

The navigation structure of the website is the core of user experience, a clear and organized multi-level classification list can not only help users quickly find the content they need, but also effectively improve the website's SEO performance.In AnQiCMS, with its flexible template tag system, achieving the intuitive and efficient display of nested list categories becomes straightforward. ### Understanding AnQiCMS's Classification Structure In the AnQiCMS admin interface, you will find that the classification function allows you to create classifications with hierarchical relationships.This means you can write an article for

2025-11-07

How does AnQiCMS automatically handle image thumbnails to optimize the display speed of website content?

In today's fast-paced online world, the speed of displaying website content, especially the speed of image loading, directly affects user experience, website bounce rate, and even search engine rankings.Large images are often the culprits that slow down website speed, but without them, the content can become dull and boring.How can one have the cake and eat it too, showing high-quality images while ensuring the website content loads quickly?

2025-11-07

How to configure AnQiCMS's pseudo-static rules to achieve personalized URL display?

## Optimize URL structure, create personalized website links: AnQiCMS Static Rule Configuration Guide In website operations, URL (Uniform Resource Locator) is not only the address of content, but also an important part of Search Engine Optimization (SEO) and User Experience (UX).A clear, meaningful, and easy-to-remember URL structure that can effectively improve a website's ranking in search engines, as well as allow visitors to understand the page content more intuitively.

2025-11-07

How to use breadcrumb navigation tags in AnQiCMS templates to enhance user experience?

In modern web design, user experience (UX) and search engine optimization (SEO) are the two cornerstones of success.A clear and intuitive navigation system can not only guide users to find the information they need easily, but also help search engines better understand the structure of the website.Among them, Breadcrumb Navigation is an effective tool to enhance these two aspects of performance.For AnQiCMS users, making good use of its powerful template tag features can easily integrate high-quality breadcrumb navigation into the website.

2025-11-07