In website content operation, providing more relevant and potentially interesting content to visitors is a key strategy to enhance user experience, extend the time spent on the website, and promote in-depth content browsing.This not only effectively guides users to explore more information, but is also an important component of 'page interactivity' in Search Engine Optimization (SEO).In such a powerful content management system as AnQiCMS, it is flexible and efficient to implement the display of related document lists on the document detail page.
Anqi CMS provides for usarchiveListSuch core template tags, they can meet the needs of various document list calls, including displaying related content on the document detail page.We can build these lists based on different logic, such as category recommendations, keyword recommendations, or even manual association.
UtilizearchiveListTag implementation related document recommendations
To implement the display of related document lists on the document detail page, we will mainly use AnQiCMSarchiveListTemplate tags. This tag has a variety of functions, and through ittypeandlikecombining parameters, it can easily realize a variety of recommendation logic. Typically, these codes are placed in your content model corresponding todetail.htmlTemplate files, for example, the detail page template of the article model might bearticle/detail.html.
Let's discuss several common implementation methods one by one:
1. Smart Classification Recommendation (based on classification and similarity)
This is the most common and basic recommendation method, that is, to recommend other related documents under the category of the current document. AnQiCMS default,type="related"The model can complete this task very well. It intelligently searches for other nearby documents in the same category as the current document, providing natural extension reading.
Place the following code snippet in your document detail page template, for example, below the main content area:
<div class="related-documents">
<h3>相关推荐</h3>
<ul>
{% archiveList archives with type="related" limit="5" %}
{% for item in archives %}
<li>
<a href="{{ item.Link }}" title="{{ item.Title }}">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="document-thumb">
{% endif %}
<span class="document-title">{{ item.Title }}</span>
<span class="document-date">{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</a>
</li>
{% empty %}
<li>暂无相关推荐文档。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
In this code block:
{% archiveList archives with type="related" limit="5" %}We called:archiveListtag, and assign the obtained document list toarchivesa variable.type="related"Tell the system to retrieve the list related to the current document.limit="5"It limits the display quantity to 5 items.{% for item in archives %}:This is a loop structure that will iterate overarchivesEach document in the list.{{ item.Link }}/{{ item.Title }}:itemRepresents the current document object in the loop, we can access its various properties through.operator, such as links (Link) and the title (Title).{% if item.Thumb %}: Here we judge whether the document has a thumbnail (ThumbIf there is one, it will be displayed. Thumbnails can make the recommendation list more attractive.{{ stampToDate(item.CreatedTime, "2006-01-02") }}:stampToDateIt is a time formatting function provided by AnQiCMS, which can convert timestamps into easily readable date formats.{% empty %}:This is a very practical tag, whenarchivesIt will display when the list is empty (i.e., no related documents are found).<li>暂无相关推荐文档。</li>Avoid blank pages or errors.
Through this method, AnQiCMS will automatically screen out the most likely content that users may be interested in based on the current document's category information, greatly reducing the maintenance cost of content operation.
2. Precise Keyword Recommendation
If your website content is heavily dependent on keywords to organize, or if you want to recommend content that is strongly relevant to the core keywords of the current document, then you can uselike="keywords"参数。This requires you to manage keywords meticulously when publishing documents.
Modify the code in the above mentioned.archiveListTag, add.like="keywords":
<div class="keyword-related-documents">
<h3>基于关键词推荐</h3>
<ul>
{% archiveList archives with type="related" like="keywords" limit="5" %}
{% for item in archives %}
<li>
<a href="{{ item.Link }}" title="{{ item.Title }}">
{% if item.Logo %} {# 也可以使用 Logo 字段作为图片 #}
<img src="{{ item.Logo }}" alt="{{ item.Title }}" class="document-logo">
{% endif %}
<span class="document-title">{{ item.Title }}</span>
<span class="document-description">{{ item.Description|truncatechars:50 }}</span> {# 截取部分描述 #}
</a>
</li>
{% empty %}
<li>暂无基于关键词的推荐文档。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
Here we usedlike="keywords"The system will analyze the keywords of the current document and use them to find other documents containing the same keywords.{{ item.Description|truncatechars:50 }}Then a filter is used.truncatecharsExtract the first 50 characters of the document description to prevent the content from being too long and affecting the layout.
To ensure the effectiveness of keyword recommendations, you need to make sure that each document has relevant and accurate keywords filled out when "Content Management" -> "Publish Document" is done in the background. Keyword library management feature (help-plugin-rewrite.md中提及的“关键词库管理”) 在这里会发挥重要作用,帮助你维护一套规范的关键词体系。
3. 手动精选关联推荐
In some specific scenarios, you may wish to decide manually which documents are related to each other, such as the next article in a series or the companion materials for a product.AnQiCMS backend document editing interface allows you to manually set “related documents”.like="relation"Parameters can be put to good use.
toarchiveListTagslikeparameter settings"relation":
<div class="manual-related-documents">
<h3>手动精选推荐</h3>
<ul>
{% archiveList archives with type="related" like="relation" limit="5" %}
{% for item in archives %}
<li>
<a href="{{ item.Link }}" title="{{ item.Title }}">
<span class="document-title">{{ item.Title }}</span>
<span class="document-views">阅读量: {{ item.Views }}</span>
</a>
</li>
{% empty %}
<li>暂无手动精选的推荐文档。</li>
{% endfor %}
{% endarchiveList %}
</ul>
</div>
当你选择like="relation"When, the system will only display those documents that have been manually selected or filled in by the operator in the background editing page of the current document.This method provides the highest degree of control, ensuring that the recommended content aligns with the operator's precise intent.
summarizing the implementation steps
- Determine recommendation strategy:Firstly, choose the most suitable recommendation method (category intelligent recommendation, keyword recommendation, or manual selection) based on your content type and operational objectives.
- 定位template file:Log in to the AnQiCMS admin panel, navigate to "Template Design" -> "Template Management".Find the detail page template file that you need to add the relevant document list.
/template/{你的模板目录}/{内容模型表名}/detail.html. - Insert code:Paste the corresponding code snippet into the appropriate location in the template file, for example, below the main content area or in the sidebar region.
- Save and test:Save the template file and access the corresponding document detail page on the front end, check whether the document list is displayed correctly.If you find layout issues, you can adjust them by modifying the CSS styles.
By using flexibilityarchiveListThe different parameters of tags, we can easily create various forms of related document recommendation functions in AnQiCMS, thereby significantly enhancing the interactivity of website content and the depth of users' browsing.
Common Questions (FAQ)
1. Why doesn't any content show up on the page even though I have configured the related document list?
When encountering this situation, it is first necessary to check the following aspects:
- Is the document data sufficient?Ensure that your website has enough documentation, and that it is categorized, keyworded, or manually linked. For example, if you are using
type="related"Perform classification recommendation, but there is only one document in your category (that is, this document), so it is naturally impossible to recommend other documents. - Is the parameter setting correct?Check carefully
archiveListLabel's parameters, such astype="related"/like="keywords"orlike="relation"Are spelled correctly. EspeciallylimitParameters, if set too small, may cause even with relevant documents cannot be displayed in full. - Content integrity:If it is
like="keywords"Pattern, please check if the current document is filled with keywords, and if other documents also contain these keywords. If it islike="relation"Pattern, please confirm whether you manually associated other documents while editing the current document in the background. - Template cache issue:AnQiCMS has