In the AnQi CMS, the Flag attribute of articles is a very practical feature, which allows us to tag articles with special 'labels', thereby achieving a unique way of display on the front end of the website.This mechanism greatly enhances the flexibility and diversity of content display, allowing website operators to easily control the display style and position of articles based on the importance, characteristics, or promotion needs of the content.
What is the article Flag attribute?
In simple terms, the Flag attribute is like a special 'mark' attached to an article, it is not the category of the article, nor is it a common tag (Tag), but is used to indicate how the article should be 'recommended' or 'highlighted' in specific scenarios.By setting different Flag properties, we can easily set some articles as the headline of the home page, slide content, recommended articles, bold display, or even as special jump links.Security CMS has preset various Flag attributes for us to directly select.
In the AnQi CMS, common Flag attributes and their codes include:
- Top News
[h]: It is usually used to mark the most important and most prominent article on the homepage of the website. - [en] Recommended
[c]:泛指被推荐阅读的内容,常用于侧边栏或相关推荐区域。 - Slide
[f]:专为幻灯片或轮播图区域设计,标记可在轮播中展示的文章。 - [en]Special Recommendation
[a]:Further recommended content than ordinary recommendations. - Scrolling
[s]:Applicable to announcements or news that need to be scrolled on the page. - Bold
[b]:Indicate that the article title or other text should be displayed in bold style to attract user attention. - Image
[p]:Emphasize that the article contains important image content, which may be used in image-text lists. - Jump
[j]Set the article link to an external jump, click to directly go to the specified URL.
These properties together constitute the foundation of the flexible content display of Anqi CMS, making the content no longer just a single list presentation, but becomes vivid according to the operation strategy.
How to set the article Flag attribute in AnQiCMS backend?
The process of setting the article's Flag attribute is very intuitive.When you edit or publish articles in the Anqi CMS backend, you will notice a section named "Recommended Attributes".Here will be listed all available Flag properties, presented in the form of checkboxes.
You can select one or more corresponding Flag attributes based on the actual needs of the article and the special style you want it to display on the front end. For example, if you want a newly published article to appear simultaneously in the 'Headline' area of the homepage and the 'Slideshow' carousel, you can check them at the same time.[h](Headline) and[f](Slide) These two properties.It is worth noting that an article can have multiple Flag properties at the same time, which provides possibilities for various display methods of the article.Set the article and save it after completion.These articles marked will be accompanied by their unique "identity tags", waiting to be called in the frontend template.
How to call and display articles with Flag attribute in front-end templates?
Presenting articles with the Flag attribute on the website frontend is a key step in utilizing the value of the Flag attribute. In the template design of Anqi CMS, we mainly use the powerfularchiveListLabel to call these special articles.
archiveListTags provideflagParameters, allowing you to precisely specify which Flag attributes of articles to retrieve. For example, to retrieve all articles marked as "头条", you can use the template.flag="h"such parameters.
The following is a basic template call example, showing how to retrieve the latest 5 articles marked as "headline" and display their titles and links:
{% archiveList headlines with flag="h" limit="5" %}
{% for item in headlines %}
<li>
<a href="{{item.Link}}">{{item.Title}}</a>
</li>
{% empty %}
<li>暂无头条文章。</li>
{% endfor %}
{% endarchiveList %}
In the above code,archiveListTagged throughflag="h"Parameters filter articles with the attribute “Top” andlimit="5"limit the display number to 5 articles。“headlinesThe variable will contain the data of these articles, and then you canforloop through and display them。“}]
Exceptflagparameters,archiveListTags also supportexcludeFlagParameter used to exclude articles with a specific Flag attribute. For example, if you want to display all recommended articles except for slide articles, you can write it like this:
{% archiveList recommended with flag="c" excludeFlag="f" limit="10" %}
{% for item in recommended %}
<div class="recommended-item">
<h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
<p>{{item.Description}}</p>
</div>
{% endfor %}
{% endarchiveList %}
In addition, if you need to determine whether a single article in the list has a certain Flag attribute,archiveListIt also supportsshowFlag=trueparameter, it will expose the article's,FlagField. For example:
{% archiveList featuredArticles with showFlag=true limit="10" %}
{% for item in featuredArticles %}
<li class="{% if item.Flag contains 'b' %}bold-title{% endif %}">
<a href="{{item.Link}}">{{item.Title}}</a>
{% if item.Flag contains 'p' %}<span>[图]</span>{% endif %}
</li>
{% endfor %}
{% endarchiveList %}
here, we checkitem.FlagField whether it contains a specific Flag code (such as'b'denotes bold,'p'indicating an image), to determine the application of different CSS styles or to display additional information.
For a single article detail page, you can also usearchiveDetailtags to get the Flag attribute of the current article, and use it for the front-end display logic judgment. For example,{% archiveDetail with name="Flag" %}The current article's all Flag attributes' string will be returned, you can further use conditional judgment in the template.
Example of practical application scenarios
The application scenarios of the Flag attribute are very extensive, which can help websites achieve more refined content operation:
- Home page headline areaSet the most important news or announcement:
[h](头条)Attribute, specifically used at the top of the homepage or in the core areaarchiveListTag call, making it get the highest exposure. - Website slideshow/carousel:Set for promotional articles or product pages used in the top carousel of the website
[f](Slide) attribute, and use it in the template of the slide areaarchiveListwithflag="f"to call it, and realize dynamic display. - Sidebar recommendation module: Modules such as "Popular Articles", "Recommended Products", etc. in the website sidebar can be set for relevant content through
[c](Recommended) or[a](Special recommendation) properties, and then through the correspondingarchiveListLabel call to fill. - Visual distinction in content list: In the ordinary article list, you can set some articles that you hope users pay special attention to
[b](Bold) property. In the template, combineshowFlag=truewith conditional judgments, to add special CSS classes to the titles of these articles, such as.bold-title, thus distinguishing them visually. - External link articlesIf an article actually guides users to external websites, it can be set
[j](Jump)attribute, and judge this attribute in the template, directly link the article to the external URL, and may addtarget="_blank"andrel="nofollow".
Through these flexible Flag attribute settings and template calls, Anqi CMS helps us achieve a thousand changes in content display, making the website content more attractive and greatly enhancing the operation efficiency.
Common Questions (FAQ)
1. Can an article have multiple Flag attributes set?
Yes, an article can have multiple Flag attributes at the same time. For example, you can set an important article as both 'Headline'[h]and 'Slide'[f]It can be displayed simultaneously in the headline area of the website homepage and the slide carousel.
2. If I set the Flag property but do not call it in the template, what will be the impact?
If you set the Flag attribute for the article, but the front-end template does not write the corresponding call logic, then these Flag attributes will have no effect on the display of the article.They are simply present in the background as metadata for the article and will not automatically display any special styles on the front end.
3. Can I customize the type of the Flag attribute or add new Flag codes?
According to the design of Anqi CMS, the built-in Flag attribute currently has a fixed 8 types (h,c,f,a,s,b,p,j)。These properties are usually sufficient to cover most common special display requirements.The autoCMS is designed to provide a simple and efficient solution, therefore the feature of custom Flag type is usually not within its core design scope.If you need more complex custom content identification, it is recommended to use the custom fields or tags of the article (Tag) to achieve this.