How does the `relatedArchive` tag display a list of related articles based on document relevance?

In the daily operation of a website, 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 the tools used for intelligent display of related article lists.

relatedArchiveTags: Make your related article list smarter

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

It should be clarified that,relatedArchiveIt is not an independent tag name, it is actuallyarchiveList(Document list) A special usage of the tag, by addingtype="related"Parameters to activate the intelligent recommendation function 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 determine the 'relevance' of an article?

The Anqi CMS provides flexible logic when handling "related articles", allowing you to choose the most suitable strategy based on your actual needs:

First, when you do not specify the association method additionally,relatedArchiveit will usethe default association logic. It will intelligently search for articles that are "close" to the current document ID in the same category.This 'closeness' usually refers to documents that are close in terms of publication time or ID sequence, which ensures that the recommended articles remain consistent with the current category theme.

Secondly, if you want to emphasize the relevance of the content theme, you can use the keywords of the article for matching. By settinglike="keywords"parameter,relatedArchiveIt will prioritize based on the current document'sfirst keywordTo get related documents. This means that if you set accurate keywords for articles in the background, the system can recommend content with similar themes more accurately.

Finally, for those who needHighly precise control of related contentThe scenario, AnQi CMS provides the option to manually set.You can manually specify 'related documents' for each article in the document editing interface of the background.At this time, just set in the taglike="relation"The system will display the list of related articles completely according to your manual configuration, which is particularly useful for scenarios where you need to emphasize specific content or carry out thematic promotion.

How to use in the templaterelatedArchiveTag?

Use in your article detail page template,relatedArchiveThe 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 Anqi CMS that we want to get a list of documents and that the type of this list is "related documents" (type="related"), showing a maximum of 10 articles (limit="10")
  • {% for item in archives %}: Due torelatedArchiveIt returns a list of articles, we need to usefora loop to iterate over each article.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, you can call them as needed, such as article link, title, thumbnail, and description.truncatechars:80The filter can ensure that the description will not be too long.
  • {% empty %}: This is a very practicalforLoop auxiliary tag, whenarchivesThe list is empty, that is, no related articles are found, it will displayemptyThe content in the block, to avoid blank pages.

Master the key parameters

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

  • type="related"This is the core parameter for activating the relevant article function.
  • limit="数字"Used to control the maximum number of related articles displayed, for examplelimit="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 manually set in the background.

It is worth noting that whentypeThe value isrelatedthen,order(Sorting) Parameters will not be supported. The system will sort according to its internal association logic to ensure the relevance of recommendations.

By flexible applicationrelatedArchiveTags 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.


Frequently Asked Questions (FAQ)

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

There may be several reasons for this situation:

  • Not the document detail page: relatedArchiveThe label must work on the document (article/product) detail page because it needs a 'current document' as a reference. If used on other pages, the list may be empty.
  • There are no adjacent or matching documents:If you are using the default association (not specifiedlikeparameter), there may not be enough "adjacent" documents in the current category. If you have usedlike="keywords"It is possible that the keywords of the current document do not match any in other articles.
  • Not manually associated:If you have set uplike="relation"But forgot to manually associate related articles in the background document editing interface, the list will naturally be empty.

2.relatedArchiveTags vs normalarchiveListWhat's the difference between tags?

relatedArchiveis a tagarchiveListA specific application scenario of the tag, 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.archiveListIt is a more general tag that can be used to retrieve lists of any type of articles (such as the latest articles, popular articles, articles of specified categories, etc.), and it requires you to manually specify various filtering and sorting conditions.
  • Mechanism: relatedArchiveWhile working, it will automatically take the current document as the center to find related documents (same category nearby, keyword matching, or manually specified).archiveListIt will be completely based on the one you pass in.categoryId/order/flagFilter and sort by parameters.
  • Parameter limitations: relatedArchive(i.e.),archiveListwithtype="related"Not supported when used together)orderParameter, as it has its own associated sorting logic.

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

InrelatedArchiveTagged,likeThe parameter can only specify one value, namelylike="keywords"orlike="relation". If you try to set at the same time or the system detects a conflict, there is usually a priority or only one takes effect (for specific behavior, please refer to the latest document description of AnQi CMS or actual test).To avoid confusion, it is recommended that you clearly choose a related logic according to your actual needs to ensure that the display of the related article list meets your expectations.