How to display a list of related documents on the document detail page, such as categorized recommendations or keyword-based recommendations?

In website content operation, providing more relevant and potentially interesting content to visitors is a key strategy to improve user experience, extend website stay time, and promote in-depth content browsing.This not only effectively guides users to explore more information, but is also an important component of "page interconnectivity" 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 a core template tag, it 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 categorized recommendations, keyword recommendations, or even manual associations.

UtilizearchiveListLabel implementation related document recommendation

To implement the display of related document lists on the document detail page, we mainly use AnQiCMS'sarchiveListTemplate tag. This tag is feature-rich, and through itstypeandlikecombination of parameters, it can easily achieve various recommendation logic. Usually, this code is placed in the corresponding content model of yourdetail.htmlIn a template file, for example, the detail page template of an 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, recommend other related documents under the category of the current document. AnQiCMS defaulttype="related"The pattern can complete this task well. It will intelligently search 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 calledarchiveListTag, assign the obtained document list toarchivesVariable.type="related"Tell the system to retrieve the list related to the current document,limit="5"which 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 looped document object, we can access.the operator to access its various properties, such as links (Link), Title (Title).
  • {% if item.Thumb %}: Here, it checks if the document has a thumbnail (Thumb), if any, is displayed. Thumbnails make the recommendation list more attractive.
  • {{ stampToDate(item.CreatedTime, "2006-01-02") }}:stampToDateIs the time formatting function provided by AnQiCMS, which can convert timestamps into readable date formats.
  • {% empty %}: It is a very practical tag, whenarchivesWhen the list is empty (i.e., no related documents are found), it will display<li>暂无相关推荐文档。</li>To avoid blank pages or errors on the page."),

In this way, AnQiCMS will automatically filter out the most likely content that users are interested in based on the classification information of the current document, greatly reducing the maintenance cost of content operation.

2. Precise Keyword Recommendation

If your website content is very dependent on keywords to organize, or you want to recommend content strongly related to the core keywords of the current document, then you can uselike="keywords"Parameters. This requires you to manage keywords carefully when publishing documents.

Modify the code in the above.archiveListAdd tags, join.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>

We used herelike="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 was 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 you have filled in relevant and accurate keywords for each document when publishing documents in the background "Content Management" -> "Publish Documents". Keyword library management function (help-plugin-rewrite.mdThe "keyword library management" mentioned here plays an important role in helping you maintain a set of standardized keyword systems.

3. Manually selected related recommendations

In certain specific scenarios, you may want to have the decision of which documents are related made entirely by humans, such as the next article in a series or supplementary materials for a product.The AnQiCMS backend document editing interface allows you to manually set 'related documents'. At this time,like="relation"Parameters can be put to good use.

toarchiveListlabel'slikethe parameter to"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>

When you chooselike="relation"At that time, the system will only display those related documents that have been manually selected or filled in by the operator on the background editing page of the current document.This method provides the highest degree of control, ensuring that the recommended content conforms to the operator's precise intention.

Summary of implementation steps

  1. Determine the recommendation strategy:Firstly, based on your content type and operational objectives, choose the most suitable recommendation method (category intelligent recommendation, keyword recommendation, or manual selection).
  2. Locate the template file:Log in to the AnQiCMS admin panel, navigate to 'Template Design' -> 'Template Management'.Find the detail page template file you need to add related document list.usually its path is similar/template/{你的模板目录}/{内容模型表名}/detail.html.
  3. Insert the code:Paste the corresponding code snippet into the appropriate location in the template file, such as at the bottom of the main content area or in the sidebar.
  4. Save and test:Save the template file and access the corresponding document detail page on the front end to check if the document list is displayed correctly.If you find any layout issues, you can adjust them by modifying the CSS styles.

By flexible applicationarchiveListDifferent parameters of tags, we can easily create various forms of related document recommendation functions in AnQiCMS, thereby significantly improving the interactivity of website content and the depth of users' browsing.


Frequently Asked Questions (FAQ)

1. Why did I configure the related document list, but no content is displayed on the page?

When encountering this situation, the following aspects need to be checked first:

  • Is the document data sufficient?Make sure your website has enough documentation and that there are classifications, keywords, or manual associations between them. For example, if you usetype="related"Perform category recommendations, but since your category only has one document (i.e., this one), it is naturally impossible to recommend other documents.
  • Is the parameter setting correct:Check carefullyarchiveListLabel parameters, such astype="related"/like="keywords"orlike="relation"Make sure the spelling is correct. EspeciallylimitIf the parameter is set too small, it may cause even with relevant documents, it may not be displayed in full.
  • Content integrity:If it islike="keywords"Pattern, please check if the current document is filled with keywords and if other documents also contain these keywords. If it islike="relation"Please confirm whether other documents were manually associated when editing the current document in the background.
  • Template caching issue: AnQiCMS has