How to use AnQiCMS template tags to get a document list (archiveList) under specified conditions?

Calendar 👁️ 59

As a senior security CMS website operator, I am well aware of the key role of efficient content management and accurate content presentation in the success of a website.In AnQiCMS, flexibly using template tags is an important way to achieve this goal.Today, we will delve into how to utilizearchiveListTemplate tag, retrieves and displays document lists based on specified conditions to meet the diverse content display needs.

MasterarchiveListLabel: The powerful foundation of content display.

In AnQiCMS template development,archiveListTags are the core tools for retrieving document lists. Whether you need to display the latest articles, popular products, content under specific categories, or even implement complex filtering and search results,archiveListCan provide strong support. It can extract document data that meets the conditions you set from the database, and display it in a loop on the front-end template.

archiveListThe basic syntax structure of tags is concise and clear, usually with{% archiveList 变量名称 with 参数 %}...{% endarchiveList %}The form appears. Wherein, "variable name" is a variable you define to carry the collection of document data received in a loop;withAfter the keyword, you can add a series of parameters to accurately control document filtering and sorting.

Core parameter details: Precisely control document acquisition

To give full play toarchiveListThe power, understanding its various parameters is crucial. The following are some of the core parameters you will use in the applicationarchiveListSome of the most commonly used core parameters when using

  • moduleId(Model ID)This parameter allows you to specify which content model to retrieve documents from. For example,moduleId="1"It is usually used to retrieve documents from the article model, andmoduleId="2"Documents that may be used to obtain product models. Accurately specifying the model ID can prevent data confusion across models and ensure professionalism.

  • categoryId(Category ID)BycategoryIdYou can specify to retrieve documents under a specific category. For example,categoryId="1"Get all documents under the category with ID 1. If you need to get documents from multiple categories, you can use commas to separate multiple IDs, likecategoryId="1,2,3"It is worth noting that if this parameter is not specified,archiveListit will attempt to automatically read the category ID of the current page. If you wish to completely disable this automatic behavior, you can explicitly setcategoryId="0".

  • excludeCategoryId(Exclude Category ID)withcategoryIdOn the contrary,excludeCategoryIdUsed to exclude documents under a specific category. This is very useful when you need to display all content except for certain categories.

  • userId(Author ID)You can use to display documents published by a specific authoruserIdparameters, for exampleuserId="1"The documents published by the author with user ID 1 will be obtained

  • parentId(Parent document ID)This parameter is very useful when there is a hierarchical relationship between documents. For example, you may need to get all the "child documents" under a certain "parent document".

  • flag(Recommended attribute)AnQiCMS provides various recommended attributes for documents, such as headlines [h], recommendations [c], slides [f], and so on. Throughflag="c"You can easily filter out documents with the "recommended" attribute, which is very helpful for displaying recommended content on the homepage or column page.

  • excludeFlag(Exclude recommended attribute)withflagsimilar,excludeFlagAllow you to exclude documents with specific recommendation attributes, such as not displaying "top news" content in a certain area.

  • showFlag(Whether to display the document's flag)By default, the recommended properties of the document (Flagfield) are not visible in list items. If you need to display these properties on the front end, for example with icons or text marks, you must setshowFlagis set totrue.

  • child(Whether to display subcategory content)When you get the documents of a category,childParameters (default totrue)Determine whether to include documents under its subcategories. If you only want to display documents of the current category itself and not include its subcategories, please setchild=false.

  • order(Sorting method)The sorting method of documents is crucial.orderParameters support multiple sorting rules:

    • order="id desc": Sort by document ID in reverse order (newest release)
    • order="views desc": Sort by view count in reverse order (most popular)
    • order="sort desc": Sort by custom order in the background (default behavior). You can choose the appropriate sorting method according to your needs.
  • limit(Display number) limitThe parameter controls the number of documents to be retrieved and displayed at one time. For example,limit="10"Only the first 10 documents will be displayed. It also supports the "offset" mode, for examplelimit="2,10"means starting from the second document and retrieving 10 items.

  • type(List type)This isarchiveListA very important parameter that determines the purpose and behavior of the list:

    • type="list": The default value, only displaying the specifiedlimitThe number of documents, not involving pagination.
    • type="page": Used for document lists that require pagination. When using this type, it is often配合paginationtags to implement pagination functionality. In addition,qParameters and custom filter parameters only take effect in this type.
    • type="related"Used to retrieve a list of related documents. It is usually used on the document detail page and can recommend related content based on the keywords of the current document or manually associated documents from the backend.
  • q(search keyword)Whentype="page"then,qThe parameter allows you to specify search keywords to filter the document list. For example,q="seo"Only documents with the 'seo' keyword in the title will be displayed. If the URL already existsq=关键词.archiveListIt will also automatically read and apply.

  • Custom Filter ParameterAnQiCMS supports custom filtering of documents through URL query parameters. If you define additional filterable fields in the content model (such as "house type"), users can filter throughurl?房屋类型=住宅This way to filter documents.

  • siteId(Site ID)In a multi-site management environment,siteIdThe parameter allows you to call document data across sites.

  • combineId/combineFromId(Combined document ID)These special parameters are used to create compound document lists, such as 'Travel routes from place A to place B'.They allow you to combine each document in the list with another specified document and reflect this combination relationship when displaying the title and link.

Document fields available in the loop body}

WhenarchiveListAfter obtaining the document set, you can useforLoop through each document and access its various field information. In the loop,itemThis represents the current document object, you can access its properties like this:{{item.Title}}/{{item.Link}}etc.

The following are some commonly used document fields:

  • Id: The unique ID of the document.
  • Title: Document title.
  • Link: The complete URL link of the document.
  • Description: Brief description of the document.
  • LogoThe cover first image URL of the document.
  • ThumbThe cover thumbnail URL of the document.
  • ImagesThe group image of the document (an array of URLs).
  • CreatedTimeThe document creation timestamp (requiredstampToDatefor formatting).
  • Views: Document views.
  • Flag: The recommended attribute of the document (required)showFlag=trueto display).
  • Category: The classification object of the document (can be accessed directly)item.Category.Titleetc.).
  • Other field parameters set for document model: By{% archiveParams params with id=item.Id %}or accessed directly{{item.自定义字段名}}Get it.

Case Study: Diversified content display.

Now, let's demonstrate through several actual code snippetsarchiveListThe powerful function.

Example one: Display the latest article list

{# 显示最新发布的文章,仅限文章模型,前10条 #}
<div class="latest-articles">
    <h2>最新文章</h2>
    <ul>
        {% archiveList articles with moduleId="1" order="id desc" limit="10" %}
            {% for article in articles %}
            <li>
                <a href="{{ article.Link }}">
                    <img src="{{ article.Thumb }}" alt="{{ article.Title }}">
                    <h3>{{ article.Title }}</h3>
                    <p>{{ article.Description }}</p>
                    <span>发布于: {{ stampToDate(article.CreatedTime, "2006-01-02") }}</span>
                </a>
            </li>
            {% empty %}
            <li>暂无最新文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Example two: Specific category product list with pagination

Assuming we want to display products under the 'Electronics' category (ID 5) and support pagination.

{# 显示电子产品分类下的产品,带分页功能 #}
<div class="product-category-list">
    <h2>电子产品</h2>
    {% archiveList products with moduleId="2" categoryId="5" type="page" limit="12" %}
        <div class="product-grid">
            {% for product in products %}
            <div class="product-item">
                <a href="{{ product.Link }}">
                    <img src="{{ product.Logo }}" alt="{{ product.Title }}">
                    <h3>{{ product.Title }}</h3>
                    <p>价格: ¥{{ product.Price }}</p>
                </a>
            </div>
            {% empty %}
            <p>该分类下暂无产品。</p>
            {% endfor %}
        </div>

        {# 分页导航 #}
        <div class="pagination-controls">
            {% pagination pages with show="5" %}
                <ul>
                    <li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}"><a href="{{pages.FirstPage.Link}}">首页</a></li>
                    {% if pages.PrevPage %}
                        <li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
                    {% endif %}
                    {% for p in pages.Pages %}
                        <li class="{% if p.IsCurrent %}active{% endif %}"><a href="{{p.Link}}">{{p.Name}}</a></li>
                    {% endfor %}
                    {% if pages.NextPage %}
                        <li><a href="{{pages.NextPage.Link}}">下一页</a></li>
                    {% endif %}
                    <li class="{% if pages.LastPage.IsCurrent %}active{% endif %}"><a href="{{pages.LastPage.Link}}">尾页</a></li>
                </ul>
            {% endpagination %}
        </div>
    {% endarchiveList %}
</div>

Example three: Display related articles on the document detail page.

On the article detail page, it is common to recommend some related articles to the current article to increase user stay time.

{# 在文章详情页显示相关文章,根据关键词推荐 #}
<div class="related-articles">
    <h3>相关推荐</h3>
    <ul>
        {% archiveList relatedDocs with type="related" like="keywords" limit="5" %}
            {% for doc in relatedDocs %}
            <li>
                <a href="{{ doc.Link }}">
                    <span>{{ doc.Title }}</span>
                    <span>({{ stampToDate(doc.CreatedTime, "2006-01-02") }})</span>
                </a>
            </li>
            {% empty %}
            <li>暂无相关推荐。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Summary

archiveListThe tag is an extremely powerful and flexible component in the AnQiCMS template system. By mastering its various parameters and the document fields available in the loop, you can achieve everything from simple content lists to complex filtering and searching

Related articles

How to call document detail data (archiveDetail) in AnQiCMS template?

As an experienced CMS website operation personnel for a security company, I know that content is the core of the website, and how to efficiently and accurately display this content is the focus of our daily work.Today, we will delve into a crucial tag in the AnQiCMS template called `archiveDetail`, which allows us to flexibly call and display detailed document data.### Understanding the core function of the `archiveDetail` tag In AnQiCMS, whether it is articles, products, or other custom model content

2025-11-06

How to create and manage new document tags in AnQiCMS?

As an experienced CMS website operation person in the security industry, I am well aware of the importance of content tags in website content organization and search engine optimization (SEO).AnQi CMS provides a straightforward and flexible label creation and management mechanism, aimed at helping operators efficiently classify content, improving user experience, and optimizing the website's performance in search engines. ### Understanding Document Tags in AnQi CMS In AnQi CMS, document tags are a powerful content association tool.

2025-11-06

What is the main difference between AnQiCMS document tags and document categories?

As an experienced security CMS website operator, I am well aware of the core status of content organization in website operation.In AnQiCMS, to manage and optimize content efficiently, we mainly rely on two powerful content organization tools: **Document Classification** and **Document Tags**.Although they are all intended to help us summarize and find content, there are significant differences in their design philosophy, functional focus, and actual application scenarios.The document classification plays a role in structuring content and serving as the main navigation skeleton in AnQiCMS.

2025-11-06

How to add custom field types to AnQiCMS content model?

As a professional who has been deeply engaged in AnQiCMS content operations, I am well aware of the importance of the flexibility of the content model in meeting the diverse needs of readers.AnQiCMS provides powerful custom capabilities in content management, especially its custom field function of the content model, which is the foundation for our efficient content creation and management.Below, I will explain in detail how to add custom field types to the AnQiCMS content model to help you better build personalized content structures.--- ### Adding Custom Field Types for AnQiCMS Content Model

2025-11-06

How to implement cross-site document data calling in AnQiCMS multi-site management?

As an experienced CMS website operation personnel of an enterprise security, I know that efficient content reuse and data integration are crucial for improving operational efficiency in multi-site management.AnQi CMS was designed with the needs of small and medium-sized enterprises, self-media operators, and users with multi-site management requirements in mind, one of its core strengths being its powerful multi-site management capabilities.This is not limited to the creation and management of independent sites, but also reflects the flexibility and convenience of cross-site document data calls.

2025-11-06

How to optimize document links for AnQiCMS's URL rewrite rule?

As an experienced website operator, I am well aware of the importance of a website's link structure for user experience and Search Engine Optimization (SEO).In the daily operation of AnQiCMS (AnQiCMS), the URL rewrite rule is one of the key tools we use to optimize document links and improve website performance.Today, I will elaborate on how AnQiCMS's pseudo-static rules can help us achieve this goal. The link to the website, like a map for users and search engines.

2025-11-06

How does AnQiCMS prevent the collection of document content and protect image copyrights?

As an experienced senior person in the field of enterprise CMS content operation, I know that content is the lifeline of the website, and the value of original content is self-evident.In this digital age, the collection of content and the infringement of image copyrights are common challenges faced by operators.Aqiy CMS is well-versed in this and has provided us with powerful tools to deal with these issues.Below, I will elaborate on how Anqi CMS builds a solid defense from both content and image levels for us.

2025-11-06

What advanced SEO tools does AnQiCMS provide to optimize document content?

As a senior CMS website operation personnel, I fully understand the importance of an efficient content management system in SEO optimization.AnQi CMS not only provides the convenience of content publishing and management, but also built-in a series of powerful advanced SEO tools, aimed at helping us better optimize website content, improve search engine visibility, and attract and retain users.Below, I will elaborate on the advanced SEO tools provided by Anqi CMS in document content optimization.

2025-11-06