How to display the list of related articles based on the document relevance using the `relatedArchive` tag?

In the daily operation of websites, how to make users naturally discover more interesting content after reading an article is the key to improving user experience, extending the time spent on the website, and even optimizing SEO effects. Anqi CMS understands this point and provides powerful template tag functions, among whichrelatedArchiveTags are exactly the tools used to display related article lists intelligently.

relatedArchiveTags: Make your related article list smarter.

relatedArchiveThe charm of tags lies in their ability to recommend a series of articles highly related to the content being viewed, either automatically or according to the rules we specify.This can not only effectively guide users to perform in-depth reading, build high-quality internal links within the site, but also significantly reduce the bounce rate of the website, making visitors stay longer on your site.

It should be clear that,relatedArchiveIt is not an independent tag name, it is actuallyarchiveList(Document list)a special usage of tags, by addingtype="related"This parameter is used to activate the smart recommendation feature for related articles. This tag is most commonly used on article or product detail pages because the logic of relevance requires a 'current document' as a reference.

How does AnQi CMS judge the 'relevance' of articles?

The 'AutoCMS' handles 'related articles' with flexible logic to judge the degree of association between articles, and you can choose the most suitable strategy according to your actual needs:

Firstly, when you do not specify the association method extra,relatedArchiveit will adoptthe default association logic.It will intelligently find articles "close" to the current document's ID within the same category.The term 'nearby' usually refers to documents that are relatively close in terms of publication time or ID sequence, which ensures that the recommended articles are consistent with the current category topic.

其次,If you want to emphasize the relevance of content themes, you can use the keywords of the article for matching. By settinglike="keywords"parameters,relatedArchiveIt will prioritize according to the current document'sThe first keywordGet the relevant documents. This means that if you set accurate keywords for the article in the background, the system can recommend content with similar themes more accurately.

Finally, for those who needHighly precise control over related contentThe scene, Auto CMS provides the option of manual settings.You can manually specify 'related documents' for each article in the document editing interface on the backend.like="relation"The system will display the related article list according to your manual configuration, which is particularly useful in scenarios where you need to emphasize specific content or carry out thematic promotion.

How to use in templaterelatedArchiveTags?

In your article detail page template, userelatedArchiveThe label is very intuitive. Here is a typical code example that shows how to retrieve and loop through the titles, links, and thumbnails of up to 10 related articles:

{# related 相关文档列表展示 #}
<div class="related-articles-section">
    <h3>相关推荐</h3>
    <ul>
    {% archiveList archives with type="related" limit="10" %}
        {% for item in archives %}
        <li>
            <a href="{{item.Link}}">
                {% if item.Thumb %}
                <img alt="{{item.Title}}" src="{{item.Thumb}}">
                {% endif %}
                <h5>{{item.Title}}</h5>
                <p>{{item.Description|truncatechars:80}}</p> {# 截取描述前80个字符 #}
            </a>
        </li>
        {% empty %}
        <li>
            抱歉,当前没有找到相关文章。
        </li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

In this example:

  • {% archiveList archives with type="related" limit="10" %}This line of code tells the security CMS that we want to get a list of documents, and the type of the list is "related documents" (type="related"), showing at most 10 articles (limit="10").
  • {% for item in archives %}Due torelatedArchiveThe returned is a list of articles, we need to usefora loop to go through each article one by one.itemis the current article object in the loop.
  • {{item.Link}}/{{item.Title}}/{{item.Thumb}}/{{item.Description}}These are the common properties of the current article object, which you can call as needed, such as article link, title, thumbnail, and description.truncatechars:80The filter can ensure that the description content is not too long.
  • {% empty %}: This is a very practicalforLoop auxiliary tag, whenarchivesThe list is empty, meaning no related articles were found, it will displayemptyThe content of the block, to avoid blank pages.

Master key parameters

To better control the display of related articles, it is crucial to understand the following parameters:

  • type="related"This is the core parameter for activating the related articles feature.
  • limit="数字":Used to control the maximum number of related articles displayed, for example.limit="5"Only 5 articles will be displayed.
  • like="keywords":Used when you want to associate articles based on keywords.
  • like="relation"When you want to use the related articles set manually in the background.

It is worth noting that whentypehas a value ofrelatedwhenorderThe parameter for sorting will not be supported. The system will sort based on its internal association logic to ensure the relevance of recommendations.

By using flexibilityrelatedArchiveLabels and the various associated logic they provide will enable you to offer your website visitors more intelligent and personalized content recommendations, greatly enhancing user stickiness and the overall value of the website.


Common Questions (FAQ)

1. Why did I setrelatedArchiveLabel, but the related article list is empty?

There may be several reasons for this situation:

  • Non-document detail page: relatedArchiveThe label must be on the document (article/product) detail page to function normally, as it requires a "current document" as a reference. If used on other pages, the list may be empty.
  • No adjacent or matching documents:If you are using the default association (not specified)likeparameter), there may not be enough "adjacent" documents in the current category. If you have usedlike="keywords",The current document's keywords may not have matching items in other articles.
  • Not manually associated:If you have setlike="relation"But forgot to manually associate related articles in the background document editing interface, the list will naturally be empty.

2.relatedArchiveTags and the usualarchiveListWhat is the difference between tags?

relatedArchiveTags arearchiveListA specific application scenario of a label, the main difference being:

  • Different purposes: relatedArchiveUsed specifically for "recommend articles related to the current document", the core being the intelligent or manual establishment of associations.archiveListis a more general tag that can be used to retrieve lists of articles of any type (such as latest articles, popular articles, articles in specific categories, etc.), and you need to manually specify various filtering and sorting conditions.
  • 工作机制:English relatedArchive在工作时,会自动以当前文档为中心,寻找关联文档(同分类临近、关键词匹配或手动指定)。EnglisharchiveList则完全依据您传入的EnglishcategoryId/order/flagParameters to filter and sort.
  • Parameter restrictions: relatedArchive(i.e.,)archiveListWithtype="related"Unsupported when used together)orderBecause it has its own associated sorting logic.

3. Can I use keyword association and manual association at the same time? If both are set, which one will take effect?

InrelatedArchivein the tag,likeOnly one value can be specified for the parameter, that is,like="keywords"orlike="relation".If you try to set at the same time or if the system detects a conflict, there will usually be a priority or only one of them will take effect (for specific behavior, please refer to the latest document description of Anqi CMS or actual testing).To avoid confusion, it is recommended that you clearly select a correlation logic according to your actual needs to ensure that the display of related article lists meets your expectations.