How to filter and display AnQiCMS document list according to category ID and recommendation attributes?

Manage website content in AnQiCMS, often need to display document lists based on different conditions.Whether you want to display the latest articles of a specific category on the homepage or highlight some recommended content in the sidebar, the system provides flexible tools to help us achieve this.Today, let's talk about how to cleverly use category ID and recommendation attributes to accurately filter and display the document list you want.

Precise positioning: filter document list by category ID

As your website content becomes richer, a clear classification structure becomes particularly important.AnQiCMS allows you to select a category for each document, which not only facilitates backend management but also provides great flexibility for frontend display.

If you want to display documents under a specific category on a page, such as only displaying the latest news from the "News Center" category, you can usearchiveListThis powerful template tag. This tag has acategoryIdParameters, you just need to pass the target category ID as a value to it. For example, suppose your "news center" category ID is 101, then the code would be like this:

{% archiveList latestNews with categoryId="101" limit="5" %}
    {% for item in latestNews %}
        <a href="{{item.Link}}">{{item.Title}}</a>
        {# 更多文档信息,如发布时间、简介等 #}
    {% endfor %}
{% endarchiveList %}

here,latestNewsThis is a temporary variable name defined for the document list,limit="5"It limited the display to only 5 of the latest documents. In this way, you can easily retrieve the corresponding document content at any location on the website based on the category ID.

It is worth mentioning that if you want to display only the documents under the current category and not include the content of its subcategories, you can further addchild=falseParameter. Conversely, if you want to set all top-level categories, you cancategoryId="0"coordinate withmoduleIdParameters to specify the model type. These detailed controls make the document display more in line with your business needs.

Highlight key points: Filter document list by recommended attributes.

In addition to categorization, AnQiCMS also provides a series of 'recommended attributes', also known as 'Flag'.These properties are like tags for content, helping you to mark important content for highlight display in different areas of the website, such as setting slides, headlines, recommendations, and so on.

When editing documents in the background, you will see an option for "Recommended Properties" where you can select multiple properties such as头条[h]/推荐[c]/幻灯[f]/特荐[a]/滚动[s]/加粗[h]/图片[p]/跳转[j]Each attribute has a corresponding letter identifier. The front-end template calls specific content through these letter identifiers.

You will also use to filter documents with specific recommendation propertiesarchiveListtags, and cooperateflagparameters. For example, if you want to display 3 documents marked as 'recommended' on the homepage, and theirflagLetters arec, the code can be written like this:

{% archiveList featuredArticles with flag="c" limit="3" %}
    {% for item in featuredArticles %}
        <div class="featured-item">
            <img src="{{item.Thumb}}" alt="{{item.Title}}" />
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            {# 更多详情 #}
        </div>
    {% endfor %}
{% endarchiveList %}

Byflag="c", the system will automatically filter out all documents marked as "recommended". If you want to exclude documents with a specific attribute, you can also useexcludeFlagParameter.

Flexible combination: dual screening of category ID and recommended attributes

The strength of AnQiCMS lies in the flexibility to combine these filtering conditions, realizing a more refined content display.

For example, you may want to display only those articles marked as "headlines" under the "Company News" category. Assuming the category ID for "Company NewshSo your code can be organized like this:

{% archiveList hotCompanyNews with categoryId="102" flag="h" limit="4" order="views desc" %}
    {% for item in hotCompanyNews %}
        <article>
            <h2><a href="{{item.Link}}">{{item.Title}}</a></h2>
            <p>{{item.Description}}</p>
            <span>阅读量:{{item.Views}}</span>
        </article>
    {% endfor %}
{% endarchiveList %}

In this example, we not only combinedcategoryIdandflagand also filtered throughorder="views desc"Sort the results by reading volume from high to low and limit the display to 4 items. If your list needs pagination, you cantypethe parameter topagethen cooperate withpaginationTags used together to provide users with a better browsing experience.

{% archiveList paginatedNews with categoryId="102" flag="h" type="page" limit="10" order="id desc" %}
    {% for item in paginatedNews %}
        <article>
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>{{item.Description|truncatechars:100}}</p>
            <span>发布日期:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
        </article>
    {% empty %}
        <p>该分类下暂无符合条件的文档。</p>
    {% endfor %}

    {# 分页导航 #}
    {% pagination pages with show="5" %}
        {# 首页、上一页、中间页码、下一页、末页的展示逻辑 #}
        {# 例如:#}
        {% for pageItem in pages.Pages %}
            <a class="{% if pageItem.IsCurrent %}active{% endif %}" href="{{pageItem.Link}}">{{pageItem.Name}}</a>
        {% endfor %}
    {% endpagination %}
{% endarchiveList %}

Through these flexible filtering and display methods, AnQiCMS makes content organization and presentation very simple and efficient.You can freely control the display form of each document list based on the website design and operational strategy, providing visitors with more accurate and valuable content.


Frequently Asked Questions (FAQ)

1. How to get the category ID or TagID of the current page to dynamically filter documents?On the category page or Tag page, AnQiCMS will automatically identify the category ID or TagID of the current page. You do not need to specify manually.categoryIdortagIdparameter,archiveListThe label intelligently reads the current context information. For example, on the category list page,{% archiveList archives with type="page" %}it will default to retrieving documents under the current category. If you need to explicitly retrieve the ID, you can use{% categoryDetail with name="Id" %}or{% tagDetail with name="Id" %}.

2. Why is the recommended attribute (Flag) set, but not displayed on the front end?First, check the template code in yourarchiveListHave you used the tag correctly?flagThe parameter, and whether the letter identifier passed matches the one set up on the backend (for example,flag="c"Recommended.Secondly, ensure that your template logic indeed includes a structure for looping through the document list and displaying the content.Finally, if it still does not display, you can check whether the document has been published on the back-end, whether it belongs to the correct category, and whether the recommended properties are correctly checked and saved.

3. How to implement pagination in the document list?To implement pagination in the document list, you need toarchiveListSet in the labeltype="page"and specify the number of documents to display per page, for examplelimit="10"Then, inarchiveListafter the end of thepaginationtag to generate page navigation links.paginationThe label will be based onarchiveListGenerated pagination data, automatically displays home page, previous page, middle page numbers, next page, and end page navigation elements, convenient for users to browse.