How to retrieve and display the document list related to the current document in AnQiCMS template?

As a website operator who deeply understands the operation of Anqi CMS, I am well aware of the core value of content strategy for user experience and website growth.High-quality content not only requires careful creation, but also needs to be intelligently organized and presented to ensure that readers can easily find more information that interests them.How to effectively display the list related to the current document on the article detail page is an important factor in enhancing user stickiness and page browsing depth.

Now, let's delve into how to implement this feature in the AnQiCMS template, by dynamically displaying relevant content to provide your readers with a seamless reading experience.

The related document list in AnQiCMS template: the key to enhance user experience

In AnQiCMS, displaying related document lists for the current document is an effective strategy to optimize the user's reading path and increase the exposure rate of the website content.After readers finish reading an article, if they can immediately see more highly related information, they will stay longer on the page, the page bounce rate will decrease, which is very beneficial for the overall data performance of the website and search engine optimization.

Understanding how AnQiCMS defines 'related' documents

AnQiCMS provides a flexible and intelligent mechanism when determining 'related' documents, which allows us to accurately present content according to actual operational needs.By default, the system will try to automatically associate other documents based on the current document's category and content similarity.This means that articles in the same category, or those that overlap in themes or keywords, are more likely to be identified as relevant content by the system.

In addition, AnQiCMS also allows us to control the association logic of related documents more finely.For example, we can specify that the matching of related documents should mainly be based on keywords, or completely rely on the manual association settings on the back-end.This multi-dimensional 'relevance' definition allows us to choose the most suitable display method based on content type and operational objectives.

Retrieve and display related documents in the template

In the AnQiCMS template system, retrieve and display the list of related documents to the current document, mainly depending on the powerfularchiveListThe tag is a core tool for content display, which can meet various content calling needs, including the call of 'related documents'.

It is worth noting that the invocation of the related document list usually occurs inDocument detail pageMiddle dot.This is because the concept of "relevant" is relative to a "current document", so only on the specific document detail page can the system accurately identify the context and retrieve the corresponding related content.

To invoke the related document, we need toarchiveListExplicitly specify in the tagtype="related"The parameter tells AnQiCMS what list is needed related to the current document.

The followingarchiveListis the key parameter used in the tag to control the behavior of related documents.

  • type="related": This is the core parameter to enable the related document list function and must be set.
  • limit: This parameter is used to control the number of displayed related documents. For example,limit="5"The maximum number of 5 related documents will be displayed. You can also uselimit="offset,count"the format, for examplelimit="2,5"indicating starting from the 2nd document, retrieve 5 documents.
  • likeThis parameter allows you to define the matching rules for related documents:
    • Not setlikeParameter (or leave blank): The system will automatically match the most closely related documents based on the category and content similarity of the current document. This is the most commonly used default behavior.
    • like="keywords": When you want related documents to mainly match based on the keywords of the current document.This requires your document to fill in accurate keywords in the background.The system will try to find other documents containing the same keywords.
    • like="relation": If you manually set the 'related documents' link in the document editing interface of the AnQiCMS backend, then this parameter will only display these manually associated documents.This provides the highest degree of manual control.

By combining these parameters, you can flexibly implement various document display logic in the front-end template.

Code practice: Display document list

Now, let's demonstrate how to retrieve and display related document lists in the document detail page template of AnQiCMS with a practical code example.

Suppose we are editing a nameddetail.htmlThe article detail page template, we hope to display up to 6 related articles below the article content, prioritizing thumbnails and publication dates.

{# 假设这里是当前文档的内容区域结束 #}
<div class="article-content">
    {# ... 当前文档的详细内容 ... #}
</div>

{# 相关文档列表区域 #}
<div class="related-articles-section">
    <h2>相关推荐</h2>
    <ul class="related-articles-list">
        {# 使用 archiveList 标签获取相关文档。type="related" 是关键,limit="6" 控制数量 #}
        {% archiveList archives with type="related" limit="6" %}
            {% for item in archives %}
            <li class="related-article-item">
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {% if item.Thumb %}
                        {# 如果有缩略图,则显示 #}
                        <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="related-article-thumb">
                    {% else %}
                        {# 没有缩略图时,可以显示一个默认占位图,或者不显示图片 #}
                        <img src="/static/images/default-thumb.jpg" alt="暂无图片" class="related-article-thumb">
                    {% endif %}
                    <h3 class="related-article-title">{{ item.Title }}</h3>
                    <p class="related-article-description">{{ item.Description|truncatechars:80 }}</p> {# 截取描述,避免过长 #}
                    <span class="related-article-date">发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                </a>
            </li>
            {% empty %}
            {# 如果没有任何相关文档,可以显示一条提示信息 #}
            <li class="no-related-articles">
                暂无更多相关文章推荐。
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In the above code:

  • {% archiveList archives with type="related" limit="6" %}This is the core call, which will retrieve up to 6 articles related to the current document and store them inarchivesthe variable.
  • {% for item in archives %}: We traversearchivesEach related article in the list, the data of each article can be found initemAccessed in the variable.
  • {{ item.Link }},{{ item.Title }},{{ item.Description }},{{ item.Thumb }}These areitemThe fields available in the object, representing the article link, title, description, and thumbnail.
  • {% if item.Thumb %}: Ensure that the article is displayed only when there is a thumbnail, otherwise a default image can be provided.
  • {{ item.Description|truncatechars:80 }}: Use a filter to truncate the description content to keep the page tidy.
  • {{ stampToDate(item.CreatedTime, "2006-01-02") }}UtilizestampToDateThe tag formats the article creation timestamp into a readable date.
  • {% empty %}This is a very practical loop control structure, whenarchivesWhen the list is empty (i.e., no related documents are found), it will displayemptyContent within the block to avoid blank pages on the page.

Optimize the display effect of the relevant documents

It is not enough to simply retrieve the data, as website operators, we should pay more attention to the presentation of the content.

  • Visual consistency: Make sure the style of the related document list is consistent with the overall design style of your website, avoiding a sense of abruptness.
  • Information refiningIn the list, the title and thumbnail are often the most attractive elements. Consider truncating the description text or only displaying brief information to keep the interface clean.
  • Click诱导Use clear titles and attractive thumbnails to encourage users to click and view more content.
  • Test and adjustAfter release, closely monitor the click-through rate and user behavior data of relevant documents. If the results are not good, you can try adjustinglimitthe number, or changelikeParameter settings, see which matching logic can best attract your readers.

By following these steps, you can flexibly and efficiently obtain and display the list related to the current document in the AnQiCMS template, thereby greatly enhancing the user's content discovery experience on the website.


Frequently Asked Questions (FAQ)

1. Why is the related document not displayed on my document detail page?

There may be several reasons for this. First, please make sure you have used the template correctly.{% archiveList archives with type="related" ... %}Label, and it is located on a document detail page because this label requires the context information of the current document.Next, check if there is truly "related" documents: if there are no other documents under the current document's category, or no related documents through keywords, manual association configuration, the list will naturally be empty.limitThe parameter was not set small enough, causing even relevant documents to not be displayed.

2. Besides automatic association, can I manually set relevant documents?

Of course you can.AnQiCMS provides a manual association feature.You can find the "related documents" setting item when editing each document in the background, and manually select other documents associated with the current document.archiveListlabel'slikethe parameter tolike="relation"These associated documents set manually by AnQiCMS will be displayed first. This gives you the greatest degree of control, ensuring that the most important or most