How to use the `archiveList` tag in AnQi CMS template to call the document list?

Calendar 👁️ 59

As an expert who has been deeply involved in the CMS content operation field for a long time, I fully understand the importance of a flexible and efficient template tag for website content display. Among them,archiveListThe tag is undoubtedly the core tool for calling the document list in the Anqi CMS template.It not only helps us accurately filter and display various types of document content, but also combines multiple parameters to meet the diverse needs of content presentation, thereby providing readers with a high-quality browsing experience.

archiveListThe purpose and basic structure of the tag

archiveListThe tag in AnQi CMS is used to retrieve document lists, whether it is a regular document list, related document list, or a document list with pagination, it can handle it. Its basic usage involves defining a variable to store the retrieved document data and cooperate withforLoop through these data.

A typicalarchiveListThe tag structure is as follows:

{% archiveList archives with type="list" limit="10" %}
    {% for item in archives %}
        {# 在这里展示文档内容 #}
        <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
        <p>{{item.Description}}</p>
        <p>发布时间: {{stampToDate(item.CreatedTime, "2006-01-02")}}</p>
    {% empty %}
        <p>抱歉,没有找到任何文档。</p>
    {% endfor %}
{% endarchiveList %}

In this example,archivesIs the variable name we define, used to storearchiveListThe document collection obtained.{% for item in archives %}Used to loop through this collection,itemIt represents each document object in the collection. When there is no document data,{% empty %}the content of the area will be displayed.

Precise control:archiveListParameter details

archiveListThe strength of the tag lies in its rich parameters, through which we can finely filter and sort the list of documents called.

Model ID (moduleId)

This parameter is used to specify the document list under which content model to retrieve. For example, if you want to retrieve the documents under the 'Article Model', you can setmoduleId="1"If you want to get the documents under the 'Product Model', it may be set tomoduleId="2". In the backend content management of Anqi CMS, each content model has its corresponding ID.

Category ID (categoryId)

categoryIdThe parameter allows you to get a list of documents under a specified category. You can pass a single category ID, such ascategoryId="5", or multiple category IDs separated by commas, such ascategoryId="1,2,3"If this parameter is not specified,archiveListAttempts to read the category ID of the current page. If you want to call the document on a non-category page but do not want to automatically read the current category, or explicitly do not want to filter by the current category, you can explicitly setcategoryId="0".

Exclude category ID (excludeCategoryId)

withcategoryIdOn the contrary,excludeCategoryIdUsed to exclude documents under a specific category. This is very useful when you need to display most of the documents but want to skip certain specific categories, for exampleexcludeCategoryId="10"All documents under the category with ID 10 will be excluded.

User ID (userId)

If you need to display documents published by a specific user, you can useuserIdthe parameters. For example,userId="1"Only documents published by users with ID 1 will be displayed.

ID of the parent document (parentId)

This parameter is used to retrieve the child documents of a specified parent document. If your content structure has a hierarchical relationship (such as an attachment list under a product details page),parentId="某个文档ID"it can be put to use.

Recommended properties (flag)

The AnQi CMS allows setting multiple recommended attributes for documents, such as 'headline', 'recommend', 'slider', and so on.flagParameters can help you filter documents based on these attributes, for example.flag="c"Only documents marked as "recommended" will be displayed. Multiple attribute values can be set by combining letters.

Exclude recommended attributes (excludeFlag)

This parameter is used to exclude documents with specific recommended attributes, such asexcludeFlag="s"Documents marked as 'scroll' will not be displayed.

Whether to list the document'sflag(showFlag)

When you want to display the recommended property tags of each document directly in the document list, you need to setshowFlagis set totrueby default,false.

Do you want to display the content of subcategories (child)

By default, when you specifycategoryIdthen,archiveListit will include the category and all documents under its subcategories (child=true)。If you only want to display the documents of the specified category itself, and not include the documents of its subcategories, you can setchild=false.

Sort method (order)

orderThe parameter determines the display order of the documents. Common sorting methods include:

  • Sort by latest release:order="id desc"
  • Sort by most views:order="views desc"
  • Sort by custom backend:order="sort desc"(This is the default sorting method, optional)

Show number (limit)

limitParameter used to control the number of returned documents. For example,limit="10"Only 10 documents will be displayed. When you do not need the pagination feature,limitit also supportsoffsetpatterns, such aslimit="2,10"means starting from the second document and retrieving 10 items.

List type (type)

This is a very critical parameter, it determinesarchiveListThe behavior pattern of the tag:

  • type="list"(Default value): Display the document in a normal list form, controlled bylimitparameters, without pagination.
  • type="page": Used for document lists with pagination functionality. When using this type, it is usually necessary to combinepaginationtags to generate pagination navigation.
  • type="related"Used to retrieve relevant documents. In this mode,archiveListit will try to retrieve other documents most relevant to the current document. It can also refine the relevance judgment by combininglikeparameters, for example,like="keywords"(Search by keyword related) orlike="relation"(Related documents set manually in the background).

When searching for keywords (q)

Whentype="page"then,qThe parameter can be used to specify the search keyword. If you include it in the URL,q=关键词.archiveListIt will automatically read and be used to search for documents with the keyword in the title. You can also specify it directly in the tag.q="您的关键词".

Custom filter parameters (Custom)

Intype="page"In mode, if your content model is configured with filterable custom fields (such as "House Type", "Price Range"), you can pass these fields as query parameters in the URL.archiveListAdvanced filtering will be performed based on these parameters. For example, if the custom field issexIts value is, it can be filtered through URL query parameterssex=男.

Site ID (siteId)

When you use the multi-site management feature of Anqi CMS, if you need to call data from other sites, you cansiteIdspecify the ID of the target site as a

combined document ID (combineId) Combine the prefix document ID (combineFromId)

These are advanced parameters used to create a combined comparison page for documents.For example, if you want to compare two products A and B, you can use product A as the main document and product B as the composite document.combineIdA combination ID will be added to the URL of the main document, for example/tour/1/c-2.htmlof which1It is the main document ID,2It is the combined document ID.combineFromIdSimilar, but the composite document is in front, for example/tour/2/c-1.html.forCan be accessed through the loop{{combine.文档字段}}or{{combineArchive.文档字段}}To access the information of the composite document.

forDocument fields available in the loop

InarchiveListofforthe loop,itemA variable represents each document object, it contains a series of fields that can be directly accessed, making it convenient for you to display in templates. The following are some common fields:

  • {{item.Id}}: The unique ID of the document.
  • {{item.Title}}: Document title.
  • {{item.Link}}: The URL of the document detail page.
  • {{item.Description}}: The summary or abstract of the document.
  • {{item.Keywords}}: The keywords of the document.
  • {{item.CategoryId}}: The ID of the category to which the document belongs.
  • {{item.Views}}: Document views.
  • {{item.Logo}}: The URL of the main cover image of the document (large image).
  • {{item.Thumb}}: The URL of the document cover thumbnail.
  • {{item.Images}}: The array of multiple document cover images, which needs to be traversed by nested loops.
  • {{item.CreatedTime}}: Document creation time (Unix timestamp), usually needs to be combined withstampToDatefilter formatting.
  • {{item.UpdatedTime}}: Document update time (Unix timestamp).
  • {{item.Flag}}: The recommended attribute mark of the document.
  • {{item.CommentCount}}: The number of comments of the document.
  • Custom field of document model: If you define additional custom fields for the document model in the background, for exampleauthororpriceThey can also be accessed through{{item.自定义字段名}}in the form of direct access.

Actual application scenarios and code examples

Let us demonstrate through several specific scenariosarchiveListThe powerful function of tags.

Scenario one: Display the latest 10 articles published

On the homepage or sidebar of the website, we often need to display the latest released content.

<div class="latest-articles">
    <h2>最新文章</h2>
    <ul>
    {% archiveList latestArchives with moduleId="1" order="id desc" type="list" limit="10" %}
        {% for article in latestArchives %}
            <li>
                <a href="{{article.Link}}" title="{{article.Title}}">
                    <img src="{{article.Thumb}}" alt="{{article.Title}}" onerror="this.style.display='none';">
                    <span class="title">{{article.Title}}</span>
                    <span class="date">{{stampToDate(article.CreatedTime, "2006-01-02")}}</span>
                </a>
            </li>
        {% empty %}
            <li>暂无最新文章。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

In this example,moduleId="1"指定的文章模型,order="id desc"Ensure that it is sorted by the latest release,type="list"andlimit="10"which controls the list format and quantity.

Page two: Article list page with pagination

On a category list page, it is usually necessary to display all the articles under the category and provide pagination navigation.

<div class="category-articles">
    <h1>{{category.Title}}</h1> {# 假设当前页面是分类页,category变量已存在 #}
    <div class="article-list">
    {% archiveList articles with type="page" limit="15" %} {# 默认会获取当前分类的文档 #}
        {% for article in articles %}
            <div class="article-item">
                <h2><a href="{{article.Link}}">{{article.Title}}</a></h2>
                <p class="meta">
                    <span>发布于: {{stampToDate(article.CreatedTime, "2006-01-02")}}</span>
                    <span>分类: <a href="{% categoryDetail with name='Link' id=article.CategoryId %}">{% categoryDetail with name='Title' id=article.CategoryId %}</a></span>
                    <span>浏览量: {{article.Views}}</span>
                </p>
                <div class="description">{{article.Description}}</div>
                <a href="{{article.Link}}" class="read-more">阅读更多</a>
            </div>
        {% empty %}
            <p>该分类下暂无文章。</p>
        {% endfor %}
    {% endarchiveList %}
    </div>

    <div class="pagination-nav">
        {% pagination pages with show="7" %}
            <ul>
                {% if pages.PrevPage %}
                    <li><a href="{{pages.PrevPage.Link}}">上一页</a></li>
                {% endif %}
                {% for p in pages.Pages %}
                    <li {% if p.IsCurrent %}class="active"{% endif %}><a href="{{p.Link}}">{{p.Name}}</a></li>
                {% endfor %}
                {% if pages.NextPage %}
                    <li><a href="{{pages.NextPage.Link}}">下一页</a></li>
                {% endif %}
            </ul>
        {% endpagination %}
    </div>
</div>

We used heretype="page"andlimit="15"To implement pagination and combinepaginationThe tag generates pagination links.categoryDetailThe tag is used to obtain the detailed information of the article's category.

Scenario three: Display related products on the product details page.

To enhance user experience and in-site traffic, we can display related products at the bottom of the product details page for the current product.

<div class="related-products">
    <h3>相关产品推荐</h3>
    <ul>
    {% archiveList relatedProducts with type="related" like="keywords" limit="5" %}
        {% for product in relatedProducts %}
            <li>
                <a href="{{product.Link}}" title="{{product.Title}}">
                    <img src="{{product.Thumb}}" alt="{{product.Title}}">
                    <span class="title">{{product.Title}}</span>
                </a>
            </li>
        {% empty %}
            <li>暂无相关产品。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

type="related"mode, archiveListIt will intelligently search for relevant documents. Herelike="keywords"Further instruct the system to match relevance based on keywords

Related articles

How are the basic conventions and file directory structure requirements for template creation in AnQi CMS?

As a senior CMS website operation personnel of an enterprise, I know that a clear and standardized template production convention and directory structure is crucial for the long-term operation and maintenance of the website.High-quality templates not only improve user experience, but also lay the foundation for SEO optimization.Next, I will elaborate on the basic conventions and file directory structure requirements of the Anqi CMS document for you.

2025-11-06

How to configure contact information and customize system global parameters in Anqi CMS backend?

As an expert in the operation of Anqi CMS, I understand that high-quality content cannot be separated from a stable backend configuration as a support.The contact information of the website and global system parameters, although it seems basic, is the key to user trust, brand image, and the normal operation of the website's functions.Now, I will elaborate on how to configure these important information on the Anqi CMS backend.

2025-11-06

How to configure the automatic image processing (WebP, compression, thumbnails) in the content settings of AnQi CMS?

As a person who is deeply familiar with AnQi CMS and proficient in website content operation, I am well aware of the importance of image optimization for website performance, user experience, and search engine ranking.AnQi CMS provides a series of powerful automatic image processing features that can help operators efficiently manage and optimize website image resources.Below, I will give a detailed introduction on how to configure the automatic image processing in the content settings of Anqi CMS, including WebP conversion, image compression, and thumbnail generation.

2025-11-06

How does the navigation setting in AnQi CMS support multi-level menus and custom navigation categories?

As a website operator who deeply understands the operation of AnQiCMS, I am well aware of the importance of an efficient and flexible navigation system for website user experience and content presentation.The AnQi CMS provides great convenience and powerful content organization capabilities to website operators through its multi-level menu support and custom navigation category features.

2025-11-06

How to use the `categoryDetail` tag to get category details in the AnQi CMS template?

Hello, I am your familiar old friend, a website operator who has been dealing with AnQiCMS for a long time.In daily content management and website optimization work, flexibly using AnQiCMS template tags is the key to improving efficiency and user experience.Today, let's delve deeply into a very practical tag: `categoryDetail`, and see how it helps us obtain detailed category information in the AnQiCMS template.

2025-11-06

How to use the `tagDataList` tag to display documents under a specified Tag in the AnQi CMS template?

As an experienced CMS website operations manager for a leading security company, I know that high-quality content and convenient user experience are the key to attracting and retaining users.Tags (Tag) serve as an important dimension for content organization, not only helping users quickly find the content they are interested in, but also an indispensable part of internal link optimization and SEO strategy.

2025-11-06

How to use `for` loop and `if` conditional judgment tags in Anqi CMS template?

As an experienced Anqi CMS website operation personnel, I am very clear about the core role of templates in content presentation.A flexible and efficient template can not only enhance the user experience but also help us achieve accurate content placement and management.In the Anqi CMS template system, the `for` loop and `if` conditional judgment tags are the two cornerstones for building dynamic and interactive web pages.They make content no longer static text blocks, but can intelligently display according to data changes.

2025-11-06

How to use the `stampToDate` tag to format timestamps in the Anqi CMS template?

In website content management, the accuracy and aesthetics of time presentation are crucial for user experience.Whether it is the publication date of the article, the update time of the product, or the submission time of the comments, a clear and consistent date format can significantly improve the readability and professionalism of the content.AnQi CMS is an efficient and flexible content management system, deeply understanding this, and provides a powerful and simple tool for template developers - the `stampToDate` tag, which is specifically used to format timestamps into various custom date and time display formats.

2025-11-06