In the AnQi CMS, the recommended feature is a very practical function in content operation.It can help us classify and label content, thereby influencing the display of these contents on the front-end list or detail pages, such as highlighting, prioritized sorting, and even changing their layout styles.Understand and make good use of these properties, and it will make your website content management more flexible and efficient.
一、In the background, set the recommended attributes for the document.
To add recommended attributes to the document, you first need to enter the Anqi CMS backend management interface.
- Enter the document editing pageNavigate to the 'Content Management' menu, select 'Document Management', then choose an existing document to 'Edit', or click 'Add New Document' to create a new document.
- Find recommended attribute optionsOn the document editing page, on the left or right side (depending on your backend layout), you will see a section named "Recommended Attributes."
- Select recommended attributes:Security CMS provides eight preset recommended attributes, each with a corresponding letter code for easy use in templates:
- Top News
[h]:通常用于标记最重要的、需要醒目展示的文章。 - [en] Recommended
[c]:标记为普通推荐内容。 - Slide
[f]:适用于需要在幻灯片或轮播图中展示的内容。 - [en]Special Recommendation
[a]:Special recommendation, more important than general recommendation. - Scrolling
[s]:Content suitable for display in scrolling news or announcement areas. - Bold
[h]This property name overlaps with 'Headline' in the document, the actual effect may need to be checked in the template implementation, but it usually indicates that the text in a list item needs to be bold. - Image
[p]:可能意味着该内容在展示时需要配合图片。 - Jump
[j]:通常用于需要跳转到外部链接或特定页面的内容。
- Top News
You can select one or more recommended properties for the document based on its actual importance and the desired display effect.These properties are like 'content tags' attached to documents, which facilitate front-end templates in filtering and displaying these tags.
English, in the front-end template, use recommended attributes to affect display and sorting
Set the recommended properties, and the next step is to use these properties to control the display of content on the front-end template. This is mainly achieved through the template tags of the Safe CMSarchiveListandarchiveDetailto achieve.
1. Call content with specific recommendation attributes
On the list page, you can usearchiveListTagsflagParameters are used to filter and call documents with specific recommendation properties. For example, if you want to display the latest 5 'Top Stories' articles on the homepage:
{% archiveList featuredArticles with flag="h" order="id desc" limit="5" %}
{% for item in featuredArticles %}
<div class="headline-item">
<a href="{{ item.Link }}">{{ item.Title }}</a>
<p>{{ item.Description }}</p>
</div>
{% empty %}
<p>暂无头条文章。</p>
{% endfor %}
{% endarchiveList %}
This code will filter out all documents that are marked ash(Top News) document, and list by publish time in descending order (id desc). You can modify the values of parameters as needed.flagfor exampleflag="c"Get recommended articles.flag="f"Get the slide article. If you need to get a document with multiple properties at the same time, you can directly combine the property letters, likeflag="hc".
2. Affect the display order of the list page
To display documents with recommendation properties at a more prominent position on the list page, there are several common strategies:
Segmented query and combined displayThis is the most commonly used and flexible method.You can first query and display documents with specific recommendation attributes (such as "Top Stories" or "Featured"), and then query and display the remaining documents.
<div class="special-recommendations"> <h3>特荐内容</h3> {% archiveList specialRecs with flag="a" order="id desc" limit="3" %} {% for item in specialRecs %} <p><a href="{{ item.Link }}">{{ item.Title }}</a></p> {% endfor %} {% endarchiveList %} </div> <div class="latest-articles"> <h3>最新文章</h3> {% archiveList latestArticles with excludeFlag="a" order="id desc" limit="10" %} {# 排除已特荐的,防止重复 #} {% for item in latestArticles %} <p><a href="{{ item.Link }}">{{ item.Title }}</a></p> {% endfor %} {% endarchiveList %} </div>Pass
excludeFlagParameters, you can avoid repeating recommended content in subsequent regular lists to ensure content diversity.Utilize
orderSort parameters:archiveListTagsorderThe parameter allows you to specify the sorting method of the document. In addition,id desc(Sorted by ID in descending order, i.e., the most recent release)views desc(Sorted by view count in descending order)sort descThe option of (sorted according to backend custom sorting). If your document backend supports setting a "sort value" (usually a