How to use the `archiveList` tag to get documents with specific recommended attributes (such as "Top Stories" or "Slideshow")?

As an experienced website operations expert, I know that the core value of the Content Management System (CMS) lies in its flexibility and content scheduling capabilities.AnQiCMS (AnQiCMS) leverages its efficient architecture based on the Go language and rich features to provide strong support for content operations.archiveListLabel, accurately retrieve and display documents with specific recommended attributes, such as the 'headlines' news of a website or important content for 'slideshow' rotation.


Advanced operation of Anqi CMS content: How to usearchiveListTags, accurate filtering and recommendation documents

In the ever-changing Internet environment, the effective presentation of content is directly related to user experience and information transmission efficiency.For content operators, how to place the most important and attractive content in a prominent position is the key to improving website activity and conversion rates.archiveListThe tag is the tool to solve this problem. It not only helps us flexibly list various documents, but also can realize the 'intelligent' scheduling of content through fine-grained recommendation attribute filtering.

UnderstandingarchiveListThe core of content scheduling

In the template system of Anqi CMS,archiveListTags are a universal tool for retrieving document lists. Whether it's articles, products, or other custom content models, as long as they are categorized as “documents”,archiveListIt can be put to use.It is not just a simple data pull, but also provides rich parameter options, allowing us to customize the required list based on categories, modules, sorting methods, or even search keywords.

When we talk about 'recommended attributes', we are actually utilizing the 'Flag' attribute set for each document in the Anqi CMS backend document management.These Flag attributes (such as headline, recommendation, slideshow, etc.) are strategic markers of the importance and display form of the document by content operators.archiveListThe cleverness of the label lies in its ability to accurately identify these Flags and thereby filter out the specific content we want to display.

Revealing the core parameters:flagThe妙use of properties

To bearchiveListFilter out documents with specific recommended attributes, the most critical parameter isflag.When adding documents in the Anqi CMS backend, we can check the 'recommended attributes' for documents, such as 'headlines[h]', 'recommended[c]', 'slides[f]', and so on.These properties correspond to short letter codes.archiveListlabels, we just need to use these letter codes asflagthe value of the parameter to complete the filtering.

For example, if you want to get the "headlines" article on the homepage of the website, the corresponding Flag code ish. Then, you can call it in the templatearchiveListlike this:

{% archiveList headlines with type="list" limit="5" flag="h" %}
    {% for item in headlines %}
    <div class="headline-item">
        <a href="{{ item.Link }}">
            <h3>{{ item.Title }}</h3>
            <p>{{ item.Description|truncatechars:80 }}</p>
        </a>
    </div>
    {% else %}
    <p>暂无头条文章。</p>
    {% endfor %}
{% endarchiveList %}

In this code block,flag="h"Explicitly tell the system to only retrieve documents marked with the 'headline' attribute.limit="5"It limits to only display the latest 5 entries.type="list"It indicates that we do not need pagination, it is just a simple list.forLoop through the obtainedheadlinesvariable, and output the document title, link, and summary. If there are no documents that meet the criteria,{% else %}Part will friendly prompt "No headline articles available", improving user experience.

Case study: Diversified content display strategies

MasteredflagAfter the parameters, we can flexibly use it in various areas of the website to achieve diversified content display.

1. Create the homepage slideshow carousel

The slide area of the website is usually used to display important content with strong visual impact and large information volume. Such documents are often accompanied by exquisite pictures and marked with the "slide" attribute (Flag code isf)

<div class="carousel-container">
    {% archiveList slides with type="list" limit="3" flag="f" order="id desc" %}
        {% for item in slides %}
        <div class="carousel-item">
            <a href="{{ item.Link }}">
                {% if item.Thumb %}
                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="carousel-image">
                {% else %}
                <img src="/static/images/default-slide.jpg" alt="默认幻灯图片" class="carousel-image">
                {% endif %}
                <div class="carousel-caption">
                    <h4>{{ item.Title }}</h4>
                    <p>{{ item.Description|truncatechars:100 }}</p>
                </div>
            </a>
        </div>
        {% else %}
        <p>暂无幻灯内容。</p>
        {% endfor %}
    {% endarchiveList %}
</div>

Here we go throughflag="f"Filter the slide content and useitem.ThumbGet the thumbnail to ensure the visual effect of the slide.order="id desc"Ensures that the latest slide content is displayed first.

2. Category page sidebar recommendation

On a specific category page, you may want to display some "recommended" articles under the category in the sidebar (Flag code is c)

<aside class="sidebar-recommendations">
    <h4>本类推荐</h4>
    <ul>
        {% archiveList recommendedArticles with type="list" categoryId=archive.CategoryId limit="10" flag="c" order="views desc" %}
            {% for item in recommendedArticles %}
            <li><a href="{{ item.Link }}">{{ item.Title|truncatechars:30 }}</a></li>
            {% else %}
            <li>暂无推荐文章。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</aside>

In this example, we not only usedflag="c"to filter recommended articles, but also combinedcategoryId=archive.CategoryIdto ensure that only recommended content from the current category is obtained.order="views desc"Then let the recommended articles with the highest number of views be displayed first. This showsarchiveListThe powerful ability of combining tag parameters, allowing you to accurately filter based on multiple conditions.

3. Get and display the document's Flag property (if needed)

Sometimes, you may want to display the recommended properties of documents directly in the article list, making it clear to the user. At this time, in addition to usingflagparameters for filtering, you also need toarchiveListaddshowFlag=trueand loop through ititem.Flagto retrieve and display it.

{% archiveList recentPosts with type="list" limit="10" showFlag=true %}
    {% for item in recentPosts %}
    <div class="post-item">
        <h3>
            <a href="{{ item.Link }}">{{ item.Title }}</a>
            {% if item.Flag %}
            <span class="post-flag">({{ item.Flag }})</span> {# 例如显示 "(h)", "(f)" #}
            {% endif %}
        </h3>
        <p>{{ item.Description|truncatechars:120 }}</p>
        <small>发布于: {{ stampToDate(item.CreatedTime, "2006-01-02") }} | 浏览量: {{ item.Views }}</small>
    </div>
    {% else %}
    <p>暂无最新文章。</p>
    {% endfor %}
{% endarchiveList %}

here,showFlag=trueLetitem.Flagproperty is available, we can display it next to the title