How to filter and display a list of articles based on their recommended attributes (such as “Top Article”, “Recommended”)?

In Anqi CMS, efficient content management is one of the key factors for website success.Article recommendation attribute, as an important part of content refined operation, it can help us display website content more flexibly, guide users to focus on key information, thereby improving the activity and conversion rate of the website.This article will delve into how to filter and display an article list based on the recommended attributes of the article (such as "Headline

Understanding the article recommendation attributes of Anqi CMS

AnQi CMS provides rich recommendation attribute settings for each published article.These properties are like the 'tags' of an article, used to mark the importance, type, or display requirements at a specific location.By reasonably setting these properties, we can easily control the display of articles in different areas of the website.

The system built-in multiple recommended properties, each property corresponds to a specific letter identifier, convenient for calling in the template:

  • Headline[h]: Often used for the most prominent news or announcements on the homepage of a website.
  • Recommended[c]: Indicates high content quality and is worth recommending to users.
  • Slide[f]: Often used for articles in the carousel or focus image area.
  • Special recommendation[a]: Articles with more specificity or exclusivity than 'Recommended.'
  • Scroll[s]: Suitable for news flashes, bulletin boards, and other short messages that need to be scrolled.
  • Bold[h]: May share the identifier with the 'Top News' attribute, usually used to highlight article titles in lists.
  • Image[p]This indicates that the article content contains important images or elements that need to be highlighted during display.
  • Jump [j]This is used to mark the article link as an external link, which will jump directly to another page when clicked.

When editing articles in the background, you can select one or more properties in the "Recommended Properties" option according to the actual situation of the article.These operations are very intuitive, just find the corresponding options on the article editing page to select them.

Filter and display the article list in the front-end template

Apply these recommended properties to the front-end display of the website, which is the core of enhancing content operation effects. Anqi CMS provides powerful template tag functions, among whicharchiveListTags are the key to achieving this goal.

1. UseflagParameters for precise filtering.

archiveListlabel'sflagThe parameter allows you to filter the list of articles to be displayed based on the recommended attributes of the articles. For example, if you want to display all articles marked as "top news" in a certain area on the homepage, you can useflag="h":

{% archiveList archives with type="list" flag="h" limit="5" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}</h5>
            <p>{{item.Description}}</p>
        </a>
    </li>
    {% empty %}
    <li>暂无头条文章。</li>
    {% endfor %}
{% endarchiveList %}

Please note: Being calledarchiveListWhen labeling, each list can only specify one recommended attribute for filtering.If you need to meet multiple attributes of an article, you may need to adjust the content release strategy or call and merge the display in multiple times.

2. UseexcludeFlagExclude articles with specific attributes

In addition to filtering articles with specific attributes, you can also useexcludeFlagParameters to exclude certain attributes of the article.This is very useful when it is necessary to avoid content repetition.

{% archiveList archives with type="list" flag="c" excludeFlag="h" limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h4>{{item.Title}}</h4>
            <p>{{item.Description}}</p>
        </a>
    </li>
    {% empty %}
    <li>暂无其他推荐文章。</li>
    {% endfor %}
{% endarchiveList %}

This code filters out all articles marked as "recommended", while excluding those also marked as "headlines", ensuring differentiated content display.

3. Enhance filtering accuracy by combining other parameters

archiveListLabels also support other parameters, such ascategoryId(Category ID),moduleId(Model ID),limit(Number of items displayed) andorder(Sorting method), you can combine them withflagorexcludeFlagCombine use to achieve more accurate article list display. For example, display the latest 5 recommended articles under a specific category:

{% archiveList archives with type="list" categoryId="10" flag="c" order="id desc" limit="5" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <img src="{{item.Thumb}}" alt="{{item.Title}}">
            <h3>{{item.Title}}</h3>
        </a>
    </li>
    {% endfor %}
{% endarchiveList %}

4. Show article recommendation attribute identification

If you want to display the recommended attributes of each article in the article list directly, you can useshowFlag=truethe parameter. After setting it, you can go throughitem.FlagTo obtain the recommended attribute letters of the article and combine it with CSS for style rendering, for example, add a red corner mark to the "top news" article.

{% archiveList archives with type="list" showFlag=true limit="10" %}
    {% for item in archives %}
    <li>
        <a href="{{item.Link}}">
            <h5>{{item.Title}}
                {% if item.Flag contains "h" %}<span>[头条]</span>{% endif %}
                {% if item.Flag contains "c" %}<span>[推荐]</span>{% endif %}
            </h5>
            <p>{{item.Description}}</p>
        </a>
    </li>
    {% endfor %}
{% endarchiveList %}

This has been usedcontainsTo judgeitem.FlagDoes the string contain a letter of a certain attribute, because an article may have set multiple recommended attributes.

Summary

The Anqi CMS article recommendation feature provides great flexibility for website content operation. By proficiently usingarchiveListlabel'sflag/excludeFlagParameters such as these, you can accurately filter and display article lists according to different operational strategies and page requirements, thereby optimizing the user's browsing experience and enhancing the exposure and attractiveness of the website's content.Flexibly combine these features to help you better manage and present the valuable content of the website.

Frequently Asked Questions (FAQ)

  1. Question: Can I use the samearchiveListIn the tag, filter multiple recommended attributes at the same time, for example, articles that are both 'headline' and 'recommended'?Answer: Anqi CMS'archiveListTags are filtered in the selection,flagThe parameter can only specify one recommended attribute at a time. This means you cannot directly go throughflag="hc"This way to filter articles that have both the 'Headline' and 'Recommendation' attributes. If you need to achieve a similar effect, you may need to set a separate recommendation attribute for articles that have both of these features when the articles are published, or by using two differentarchiveListCall and combine front-end logic to handle.

  2. Question: If an article has set multiple recommendation attributes (such as "Top[h]" and "Slide[f]"), when I call in the front-endarchiveListUseflag="h"Will this article containing multiple properties be displayed?Answer: Yes. When you callflag="h"When, all articles that contain the recommendation attribute "h" at least will be filtered out, regardless of whether they also have other recommendation attributes.flagThe parameter is for matching whether the article "includes

  3. Ask: I have set the recommendation attribute for the article in the background, but the front-end page does not display as expected. What could be the reason?Answer: This usually has several common reasons. First, please check the template code in yourarchiveListlabel'sflagThe parameters are filled in correctly and consistent with the recommended attribute letter identifier set in your background (case-sensitive). Secondly, confirmarchiveListOther parameters of the tag, such ascategoryId/moduleIdorlimitWhether it unintentionally restricted the display of the article.After making changes to the content in the Anqicms background, sometimes you need to clear the system cache to see the latest effects on the front page. You can try to perform operations in the 'Update Cache' feature of the background management interface.