How to keep visitors immersed in your site after they have finished reading an exciting article and discover more interesting information?One of the answers is to intelligently display related documents. This can effectively improve user experience, extend the time users spend on the website, and for search engine optimization (SEO), it can also help spiders better crawl and understand the website structure through the construction of internal links, thereby improving the relevance of the content and the overall weight of the website.
In Anqi CMS, obtaining and displaying the related document list is not a complex matter.This is due to the flexible template tag system of the system, which allows us to convert technical information into practical content display in a very intuitive way.
Understand the association mechanism of Anqi CMS
Safe CMS considered the interconnection of content from the beginning of its design.It can understand the 'relevance' between content from multiple dimensions, such as through the classification of documents, keywords, or even the theme of the content itself.At the same time, the system also allows us to manually specify some associations, providing great flexibility for content operations.
We will mainly use it in templatesarchiveListThis powerful tag is used to call the document list and specify the relevant documents to be retrieved through itstypeparameters.
Core feature: usearchiveListtags to display relevant documents
The most direct way to display related documents at the bottom of the document detail page is to usearchiveListLabel, andtypethe parameter to"related". The system will intelligently filter out other documents closest to the current document based on the content, classification, and other factors.
We can place the code in this way:
<section class="related-articles">
<h3>你可能还会喜欢:</h3>
{% archiveList archives with type="related" limit="5" %}
{% for item in archives %}
<article class="related-item">
<a href="{{ item.Link }}">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="related-thumb">
{% endif %}
<h4 class="related-title">{{ item.Title }}</h4>
</a>
<p class="related-description">{{ item.Description|truncatechars:80 }}</p>
</article>
{% empty %}
<p>目前没有找到与当前内容相关的推荐文档。</p>
{% endfor %}
{% endarchiveList %}
</section>
This code first declares asection, titled "You might also like:"
Next,archiveListThe tag will try to get 5 articles related to the current document and store them inarchivesIn a variable. We useforLoop througharchivesTo generate a link for each article containing the title, thumbnail, and summary. If the system does not find any related documents,{% empty %}The content will be displayed, to avoid blank pages.
here,limit="5"The parameter controls the number of relevant documents displayed, you can adjust this number according to the page layout and content strategy.item.ThumbUsed to display the article thumbnail,item.Description|truncatechars:80Then it will截取the article introduction in the first 80 characters,ensuring the layout is tidy.
Deep customization: usinglikeParameters improve the accuracy of relevance
In addition to the system automatically determining relevance, Anqi CMS also provideslikeparameters, allowing us to finely control the matching logic of relevant documents. This parameter is particularly useful when usingtype="related"it.
Match based on keywords:like="keywords"
If your documents are all set with detailed keywords (you can fill in the "Publish Document" interface in the background), then you can tell the system to prioritize matching related documents based on these keywords. Whenlikeis set to"keywords"When, the system will find other documents containing the same keywords as the first keyword of the current document.
<section class="keyword-related-articles">
<h3>基于关键词的推荐:</h3>
{% archiveList archives with type="related" like="keywords" limit="5" %}
{% for item in archives %}
<article class="related-item">
<a href="{{ item.Link }}">
<h4 class="related-title">{{ item.Title }}</h4>
</a>
<p class="related-description">{{ item.Description|truncatechars:80 }}</p>
</article>
{% empty %}
<p>目前没有找到基于关键词的推荐文档。</p>
{% endfor %}
{% endarchiveList %}
</section>
This method is suitable for sites with highly segmented content and standardized keyword management.
Manually associated dependencies:like="relation"
Sometimes, we may need a more precise, manually intervene in the "relevance".For example, a product page needs to be associated with a specific review article, or a summary article needs to link to several articles supporting core viewpoints.The Anqi CMS allows us to manually associate other documents in the background document editing interface. Whenlikeis set to"relation"then,archiveListOnly these manually associated documents will be displayed.
To use this feature, you need to find the "Other Parameters" section (usually expandable) while editing documents in the background, where there will be a "Related Documents" setting item, where you can add the documents you want to associate.
<section class="manual-related-articles">
<h3>编辑精选推荐:</h3>
{% archiveList archives with type="related" like="relation" limit="5" %}
{% for item in archives %}
<article class="related-item">
<a href="{{ item.Link }}">
<h4 class="related-title">{{ item.Title }}</h4>
</a>
<p class="related-description">{{ item.Description|truncatechars:80 }}</p>
</article>
{% empty %}
<p>目前没有编辑精选的推荐文档。</p>
{% endfor %}
{% endarchiveList %}
</section>
The advantage of this model is that it has a very high relevance, fully in line with the intentions of content operators.
Combined with classification, it further expands the relevance.
In addition to the above.type="related"The usage, we can also combine categories to get relevant documents.For example, when reading an article about "AnQi CMS template creation", we may want to see other articles in the same category.
This can be achieved by getting the current document category ID, thenarchiveListfiltering tags by category ID:
”`twig {% archiveDetail currentArchiveId with name=“Id” %} {# Get the current document ID #} {% archiveDetail currentCategoryId with name=“CategoryId” %} {# Get the current document category ID #}
<h3>同分类最新文档:</h3>
{% archiveList archives with type="list" categoryId=currentCategoryId excludeCategoryId=currentArchiveId order="id desc" limit="5" %}
{% for item in archives %}
<article class="related-item">
<a href="{{ item.Link }}">
<h4 class="related-title">{{ item.Title }}</h4>
</a>
<p class="related-description">{{ item.Description|truncatechars:80 }}</