How to display the list of related documents in AnQiCMS template?

As a website operator who has been deeply involved in the CMS of AnQi for many years, I know that effectively guiding users to discover more interesting content is crucial for enhancing user stickiness and the depth of website visits.Among them, the 'related document list' is undoubtedly one of the core functions to achieve this goal.It not only helps users conveniently explore more related topics, but also has a positive impact on the internal link structure and SEO optimization of the website.

AnQi CMS provides a powerful and flexible tag system in template design, making it a relatively direct operation to display related document lists on the document detail page. By utilizing built-inarchiveListLabels, and with specific parameters, we can easily implement this feature.

Understand the "related documents" mechanism of Anqi CMS

AnQi CMS defines "related documents" as content that is associated with the document currently being viewed in some aspects.This association can be based on the classification of documents, keywords, or manual association in the background.It is worth noting that the related document list is usually only applicable to the document detail page, as its logic revolves around the current document.The system will try to find documents with the same category or shared keywords based on the current document ID.

Core tags:archiveListwithtype="related"

In the Anqi CMS template system, the main tag used to obtain the list of related documents isarchiveList. This tag is very versatile, not only can it be used to display a list of documents or pagination lists, but by settingtype="related"parameters, it can intelligently extract documents related to the current document.

archiveListThe label is set astype="related"At that time, it also supports a keylikeparameter, used to further refine the matching logic of the relevant document.

  • Default association: When not specifiedlikeWhen a parameter is specified, the system will automatically retrieve the nearest documents in the same category based on the current document's ID. This is a natural association based on category and time/ID sequence.
  • Based on keyword association (like="keywords"): If you want the recommendation of related documents to be more focused on the similarity of content topics, you can setlike="keywords".In this mode, the system extracts the first keyword of the current document and uses it as a basis to search for other documents containing the same keyword as relevant content.This is very useful for a website with a clear content theme.
  • Based on backend manual association (like="relation")For some scenarios that require fine-grained control of related recommendations, such as product association recommendations on e-commerce websites, operators may want to manually specify which documents are related. This can be done by setting the "related documents" field when editing documents in the background and using the template.like="relation"Ensure that only these explicitly specified documents are displayed.

excepttypeandlikeOutside the parameters,archiveListTags also supportlimit(Control the number of displayed items),moduleId(Specify the content model, such as the article model or product model),siteIdParameters such as "specified site under a multi-site environment" to meet more detailed call requirements.

Actual operation: How to display a list of related documents in the template.

We need to add the corresponding tag code in the template file (for example) to display the list of related documents in the AnQi CMS template.{模型table}/detail.htmlorarchive/detail.html)

Here is a general code example that demonstrates how to retrieve and display the default list of related documents:

<div class="related-articles-section">
    <h3>相关推荐</h3>
    <ul>
        {% archiveList archives with type="related" limit="5" %}
            {% for item in archives %}
            <li>
                <a href="{{item.Link}}">
                    <img src="{{item.Thumb}}" alt="{{item.Title}}">
                    <h4>{{item.Title}}</h4>
                    <span>{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                </a>
            </li>
            {% empty %}
            <li>
                暂无相关文档。
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

In this example:

  • archiveList archives with type="related" limit="5"We calledarchiveListLabel, set its type torelatedLimiting to display up to 5 related documents. The result set is namedarchives.
  • {% for item in archives %}:Traversearchivesarray,itemThe variable represents each related document.
  • {{item.Link}}: Output the link of the related document.
  • {{item.Thumb}}: Output the thumbnail of the related document.
  • {{item.Title}}Output the title of the relevant document.
  • {{stampToDate(item.CreatedTime, "2006-01-02")}}Format the creation time of the document.
  • {% empty %}...{% endfor %}If:archivesIf empty (i.e., no relevant document is found), then display the prompt 'No relevant document available'.

If you need to associate based on keywords, you can modify it in this wayarchiveListTags:

<div class="related-articles-by-keywords">
    <h3>相关主题文档</h3>
    <ul>
        {% archiveList archives with type="related" like="keywords" limit="5" %}
            {% for item in archives %}
            <li>
                <a href="{{item.Link}}">
                    <h4>{{item.Title}}</h4>
                </a>
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

If you want to display the relevant documents manually specified by the background, then uselike="relation":

<div class="explicitly-related-documents">
    <h3>运营推荐文档</h3>
    <ul>
        {% archiveList archives with type="related" like="relation" limit="5" %}
            {% for item in archives %}
            <li>
                <a href="{{item.Link}}">
                    <h4>{{item.Title}}</h4>
                </a>
            </li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Optimization and considerations for displaying relevant content

In the operation, simply displaying relevant documents is not enough, we also need to consider how to optimize their display effect to better serve users and the goals of the website.

  • Enhance relevanceSystem-provided features: excludinglikeParameters, can also be optimized through document classification and keyword settings to ensure the accuracy and relevance of the content.For some core content, it is considered to manually specify relevant documents in the background to provide more accurate recommendations.
  • User experience and interface designThe layout and style design of the related document list is crucial.Consider displaying a thumbnail, a brief description, and the publish time for each document to help users quickly determine if they are interested.Ensure the list is easy to read and does not distract the user from the main content.
  • Loading performance:limitParameters can effectively control the number of related documents, avoiding loading too much data at once, thereby optimizing page loading speed. For high-traffic websites, it is crucial to setlimitvital.
  • Placement locationThe related document list is usually placed at the end of the document content or in the sidebar, so that it can cater to the user's interest after reading the main content without disrupting their reading flow.

By using the above method, we can take advantage of the powerful template tag system of Anqie CMS to create a comprehensive and user-friendly document recommendation module for the website, thereby enhancing the value of the website's content and user experience.


Frequently Asked Questions (FAQ)

Why is my document detail page not displaying any related documents?

There may be several reasons for this. First, please confirm whether you have used it on the document detail page.archiveListtags and settype="related"Check if there are other documents under the category of the current document, if the number of documents is too few, the system may not be able to find enough related content. If you have usedlike="keywords"Please ensure that the current document has at least one keyword and that other documents also share the same keyword. If you have usedlike="relation"Check whether the current document is manually associated with other documents in the background. Finally,limitParameter setting too low may also cause no content to be displayed, try setting it higher.

How to display the list of related documents based on shared tags (Tag)?

Of Security CMSarchiveListThe tag is intype="related"The mode does not directly support association through Tag. However, you can achieve a similar effect by the following two methods:

  1. Indirect method: using keywordsWhen setting tags for documents in the background, you can also use some tags as keywords for the documents, then use{% archiveList archives with type="related" like="keywords" limit="N" %}tags, the system will match based on the keywords.
  2. combined tags:tagList+archiveListYou can first usetagListto get all the tags of the current document, then iterate over these tags, and use them for each tagtagDataListTag to display the documents under this tag. This method will display multiple lists of related documents grouped by tag, and may require some additional logic to deduplicate or merge.

Can I customize the matching rules for 'related documents', not just rely on categories or keywords?

archiveListTag provided.type="related"cooperatelike="keywords"orlike="relation"The parameters have already provided a more flexible matching rule.like="relation"Allow you to manually specify related documents in the background, providing the highest degree of customization. If these built-in options still cannot meet your special needs, such as complex matching based on specific custom fields in the document content model, it may require in-depth secondary development of the Anqi CMS backend logic, or in the template layer through more complex logic (such as first obtaining the value of a certain custom field of the current document, and then using it to ...archiveListofqThe parameter searches for the matching document, which will increase the complexity of the front-end template). Usually, keywords and manual association can meet most operational needs.