How to use the AnQiCMS document list tag to display content for specific categories or recommended attributes?

In AnQi CMS, efficiently managing and displaying website content is the key to improving user experience and website operation effectiveness. Whether you want to display the latest articles of a specific category on the homepage or highlight products with the "recommended" attribute, AnQi CMS provides the document list tag (archiveListThese are the core tools to meet these requirements. Its flexible parameter configuration allows us to accurately control content retrieval, transforming technical details into accessible operational strategies.

Understand the document list labelarchiveList

archiveListThe tag is a powerful function in the AnQiCMS template system used to retrieve and display a list of documents (including articles, products, and other content models).By carefully configuring its parameters, we can easily achieve various customized content display requirements.

This is the basic structure of the tag:

{% archiveList 变量名 with 参数 %}
    {% for item in 变量名 %}
        {# 在这里展示每个文档项的具体内容 #}
    {% empty %}
        {# 如果没有内容,这里可以显示提示信息 #}
    {% endfor %}
{% endarchiveList %}

Among them,变量名for examplearchives) is a name we specify for the document list we retrieve, for easy reference in loops.with 参数It is the key to defining content filtering and sorting rules.

Precise filtering: control the source and characteristics of content

To display specific categories or content with recommended attributes, we need to focus on it.archiveListSeveral core parameters of the tag:

  1. Specify the content model (moduleId)There may be various types of content on the website, such as articles, products, cases, etc. These are defined as different "content models" in AnQiCMS. ThroughmoduleIdParameters, we can clearly tell the system which content model document needs to be called. For example, if you want to get a list of articles, you can setmoduleId="1"If it is a product list, it may be set tomoduleId="2"(Specific)moduleIdYou can view it in the background "Content Model" management).

  2. Retrieve by category (categoryId)This is one of the most commonly used content filtering methods. If you want to display all articles under a specific category on a page, or show the latest news of a category on the homepage,categoryIdParameters can be put to good use. For example, you can specify the ID of a single category, such ascategoryId="5"; You can also specify multiple categories at the same time, separated by commas, such ascategoryId="5,8,12". It is worth noting that if yourarchiveListThe tag is placed on a category page, by default the system will try to read the current category ID. If you want to prevent this automatic reading behavior, you can explicitly setcategoryId="0".

  3. Display recommended attribute content (flag)AnQiCMS provides rich "recommended attributes" for document content, these attributes are like tags for content, used to mark the specificity of the content.For example, you can mark important articles as "Top News", and hot-selling products as "Recommended".头条[h]/推荐[c]/幻灯[f]/特荐[a]/滚动[s]/加粗[h]/图片[p]/跳转[j]. To display content with specific recommended attributes, just add the corresponding attribute letter after the parameter. For example,flag.flag="c"All content marked as "recommended" will be retrieved.

  4. Content sorting (order)The order of content display is also important.orderThe parameter allows you to sort content based on different criteria.

    • order="id desc":Sorted by document ID in descending order, usually used to display the latest released content.
    • order="views desc":Sorted by view count in descending order, suitable for displaying popular or highly关注的 content.
    • order="sort desc": Sort by the custom sorting value in descending order, this parameter is very useful if you have manually set the sorting for the document in the background.
  5. Limit the display quantity (limit)To avoid too much content on the page,limitThe parameter can control the number of documents displayed. For examplelimit="10"It will only display the latest 10 items. When pagination is needed,limitthe parameter is also used with the pagination label (pagination)配合使用。

Practical Application: Scenario Example

Let's see how to apply these parameters through several specific scenarios:

Scenario One: Display the latest 5 articles under the "Company News" category on the homepage

Assuming your 'Company News' category ID is10, the content model is1(Article model). To retrieve the latest 5 articles under this category, you can write the code like this:

<div class="news-section">
    <h3>公司新闻</h3>
    <ul>
        {% archiveList latestNews with moduleId="1" categoryId="10" order="id desc" limit="5" %}
            {% for item in latestNews %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {{ item.Title }}
                    </a>
                    <span>发布日期:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </li>
            {% empty %}
                <li>暂无公司新闻。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

This code will find the latest 5 articles from the article model with category ID 10 and list their titles and publication dates.

Scenario two: Display 3 'Recommended' products in the sidebar of the product list page

Assuming the content model ID of the product is2. Do you want to display products tagged as 'Recommended' (flag="c")

<div class="recommended-products">
    <h4>推荐产品</h4>
    <ul>
        {% archiveList recommendedProds with moduleId="2" flag="c" limit="3" %}
            {% for item in recommendedProds %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {% if item.Thumb %}<img src="{{ item.Thumb }}" alt="{{ item.Title }}"/>{% endif %}
                        <p>{{ item.Title }}</p>
                    </a>
                </li>
            {% empty %}
                <li>暂无推荐产品。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Here we go throughflag="c"Filter out recommended products and display their thumbnails and titles.

Scenario three: Display the top 3 articles with the highest views under a specific category.

If you want to display the most popular articles under this category on a special page, you can combinecategoryIdandorder="views desc":

<div class="top-articles">
    <h3>热门文章</h3>
    <ul>
        {% archiveList hotArticles with moduleId="1" categoryId="current" order="views desc" limit="3" %}
            {% for item in hotArticles %}
                <li>
                    <a href="{{ item.Link }}" title="{{ item.Title }}">
                        {{ item.Title }}
                    </a>
                    <span>浏览量:{{ item.Views }}</span>
                </li>
            {% empty %}
                <li>暂无热门文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

HerecategoryId="current"It is an assumption, representing the current category ID (it is usually automatically obtained on the category detail page). If it is not on the category detail page, you need to replace it with the specific category ID.

How to improve content operation effectiveness

  • Flexible use of recommendation attributes:The website is operational, content distribution and highlighting key points are crucial.The recommended attributes of AnQiCMS provide great flexibility, allowing you to adjust the priority of content at any time based on promotional activities, hot events, or content importance.
  • Optimize the structure of the content model:Combine with custom content model fields,archiveListLabels can retrieve more personalized data (such as product prices, author information, etc.), making content display richer and more accurate. ByarchiveParamsLabel, it can be further used to obtain these additional fields in the loop.
  • Rational planning of the classification system:Clear classification not only facilitates user search but also makescategoryIdThe application of parameters more intuitive and effective.
  • Balancing performance and experience: limitThe use of parameters can effectively control the amount of content loaded each time,配合分页(whentype="page"),to avoid the page being too long and slow to load, improving user experience.

Through proficiencyarchiveListAll kinds of parameter combinations of tags, you will be able to easily build a website with rich content, flexible layout, and in line with operation strategies under the empowerment of AnQiCMS, so that content can maximize its value.


Frequently Asked Questions (FAQ)

  1. Question:archiveListin the labelcategoryIdCan the parameter specify multiple categories? How can it be specified?Answer: Yes,categoryIdThe parameter can specify multiple categories. You just need to use English commas,Separate different category IDs, for examplecategoryId="1,5,8"Thus,archiveListThe tag will retrieve the content under these specified categories.

  2. How do I ask:archiveListIn the tag, how do I call the custom content model field (for example, article author or product price)?Answer:archiveListThe tag itself provides some standard fields (such asTitle/Link)。To call custom fields, you need to usearchiveListWithin a loop, for eachitemUsearchiveParamstags to retrieve. For example:

    {% archiveList archives with moduleId="1" limit="5" %}
        {% for item in archives %}
            <h3>{{ item.Title }}</h3>
            {% archiveParams params with id=item.Id %}
                {% for param in params %}
                    {% if param.FieldName == "author" %} {# 假设您自定义了一个字段名为 "author" #}
                        <p>作者: {{ param.Value }}</p>
                    {% endif %}
                {% endfor %}
            {% endarchiveParams %}
        {% endfor %}
    {% endarchiveList %}
    

    If you set the English call field when customizing the field (such asauthor), you can also try to use{{ item.author }}call, but througharchiveParamsloop traversal is more general.

  3. Ask: If I set the 'recommended' attribute (such as 'recommended[c]') for an article in the background, how can I display these recommended articles through thearchiveListtag on the front end?Answer: To display articles with specific "recommended" properties, you need to specifyarchiveListSet in the labelflagthe parameter. For example, to display all articles marked as "recommended[c]", you can write: {% archiveList recommendedArticles with moduleId="1" flag="c" limit="10" %}This allows you to filter and display content with the recommended attribute.