How to get the list of related articles for the current article (based on category, keywords, or manual association)?

Calendar 👁️ 61

As a website operator who deeply understands the operation of AnQiCMS, I know that high-quality content and user experience are crucial to the success of a website.The related articles can not only effectively extend the user's stay on the site, increase the page views, but also benefit the internal link optimization (SEO) of the website.AnQiCMS provides a flexible way to retrieve and display these related contents, meeting the operational needs of different scenarios.

Overview of the mechanism for linking articles in AnQi CMS

In AnQiCMS, the main way to get related articles is through the core ofarchiveListTemplate tag implementation. This tag has powerful filtering and sorting capabilities, and can retrieve article lists based on various conditions, including a special one for associating articles.type="related"Parameters. By adjustingarchiveListThe parameter allows us to easily implement article recommendations based on categories, keywords, or manual association in the background.This provides operators with great freedom to ensure that users can always find more content they are interested in.

Retrieve associated articles based on the article category

The most common way to associate articles is to recommend them based on the category they belong to.When a user browses a specific article, they are usually also interested in other articles in the same category.In AnQiCMS, we can get the category ID of the current article and then usearchiveListUse tags to retrieve other articles in the category.

Firstly, we need to obtain the category ID of the current article in the template. This can be done byarchiveDetailTag implementation. Once we get the category ID, we can use it asarchiveListlabel'scategoryIdA parameter value. For example, if the current article's category ID is123, we can setcategoryId="123"Fetch the articles under this category. At the same time, to avoid duplicate display of the current article, we usually need to configure the relevant article list appropriately in the background.limitThe parameter can control the number of articles displayed, ensuring the simplicity and efficiency of the related article area.

Get related articles based on keywords or tags.

In addition to categories, keywords or tags are also important links connecting the content of articles.AnQiCMS allows us to intelligently recommend related content based on the keywords of the current article.This method is particularly effective for articles that cross categories but have similar themes.

To implement keyword-based associated article recommendation, we still usearchiveListTags, and settype="related". On this basis, by addinglike="keywords"Parameter, AnQiCMS will automatically parse the keywords or tags of the current article and search for other articles with similar content accordingly.This means that if multiple articles use the same core keywords or tags, they will be interconnected to form a content matrix, greatly improving the discoverability of the content.The importance of setting keywords and tags accurately when publishing articles is fully manifested at this moment.

Through manual association to obtain articles

In certain special cases, website operators may need to control the display of related articles more finely, for example, when promoting specific content, creating special topic pages, or guiding users to read specific series of articles.AnQiCMS provides the function of manually associating articles for this.

You can use it to specify the related articles of an article explicitly in the backgroundarchiveListLabel collaborationtype="related"andlike="relation"Parameters. This means that the system will no longer automatically calculate relevance based on categories or keywords, but will only display those articles that are manually specified by the operations personnel in the backend editing interface as relevant content for the current article.This feature grants the operation personnel the highest degree of freedom, enabling them to accurately guide users to the preset content path and implement more complex operation strategies.

A practical example of calling related articles in the AnQiCMS template

To demonstrate how to obtain and display related articles in the AnQiCMS template more intuitively, here is a comprehensive example.Suppose we are at the bottom of an article detail page, hoping to display articles in the same category, recommended based on keywords, and manually associated.

{# 首先,获取当前文章的ID和分类ID #}
{% archiveDetail currentArticleId with name="Id" %}
{% archiveDetail currentCategoryId with name="CategoryId" %}

<div class="related-articles-section">
    <h3>更多相关文章</h3>

    {# 方式一:根据当前文章分类ID获取关联文章 #}
    <div class="related-by-category">
        <h4>同类推荐</h4>
        <ul>
            {% archiveList categoryRelatedArchives with categoryId=currentCategoryId type="list" limit="5" %}
                {% for item in categoryRelatedArchives %}
                    {# 排除当前文章本身 #}
                    {% if item.Id != currentArticleId %}
                        <li>
                            <a href="{{item.Link}}">{{item.Title}}</a>
                            <span>- {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        </li>
                    {% endif %}
                {% empty %}
                    <li>暂无同分类文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>
    </div>

    {# 方式二:根据关键词智能推荐关联文章 #}
    <div class="related-by-keywords">
        <h4>关键词推荐</h4>
        <ul>
            {% archiveList keywordRelatedArchives with type="related" like="keywords" limit="5" %}
                {% for item in keywordRelatedArchives %}
                    {# 排除当前文章本身 #}
                    {% if item.Id != currentArticleId %}
                        <li>
                            <a href="{{item.Link}}">{{item.Title}}</a>
                            <span>- {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        </li>
                    {% endif %}
                {% empty %}
                    <li>暂无关键词相关文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>
    </div>

    {# 方式三:手动关联的文章 #}
    <div class="related-by-manual">
        <h4>精选推荐</h4>
        <ul>
            {% archiveList manualRelatedArchives with type="related" like="relation" limit="5" %}
                {% for item in manualRelatedArchives %}
                    {# 排除当前文章本身 #}
                    {% if item.Id != currentArticleId %}
                        <li>
                            <a href="{{item.Link}}">{{item.Title}}</a>
                            <span>- {{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
                        </li>
                    {% endif %}
                {% empty %}
                    <li>暂无手动关联文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>
    </div>
</div>

In this example, we first obtained the current article'sIdandCategoryId. Then, we used the tag three timesarchiveListin different waystypeandlikeCombining parameters to retrieve associated articles under different logic. In each loop, we pass through{% if item.Id != currentArticleId %}Ensure that the currently reading article is not displayed repeatedly.{% empty %}The tag elegantly handles the situation where no related articles are found, enhancing user experience.

Operational suggestions to improve the effect of related articles

As an operations manager, merely implementing the call to related articles is not enough; we also need to think about how to maximize its effect.

Firstly, the display position of the related articles is crucial. Usually, they appear below the article content, in the sidebar, or at the end of the article, ensuring that users can naturally discover more related information after completing the current content reading.Secondly, the number of displays should be moderate, usually recommended to display 3 to 8 articles, to avoid information overload or insufficient information.The attractiveness of the title and thumbnail also directly affects the click-through rate, therefore ensure that the associated articles have high-quality cover images and concise, clear titles.

In addition, regularly reviewing and optimizing keywords and tags is a long-term mechanism to improve the accuracy of keyword recommendations.For manual association, it should be combined with data analysis to associate the key content of the performance **or the user conversion path to achieve** the operation effect.These flexible tools provided by AnQiCMS, combined with refined operational strategies, will become an indispensable part of your website's content ecosystem.


Frequently Asked Questions (FAQ)

Ask: Why are my related articles not displayed, or displayed inaccurately?Answer: There may be several reasons why related articles do not display or are inaccurate. First, please check if your template code is usingarchiveListtags and their parameters, especiallycategoryId/typeandlikeWait. Next, confirm whether the current article has related content, such as other articles in the same category, whether the keywords/tags are set correctly, or whether other content is manually associated with the article in the background.Furthermore, if you are usinglike="keywords"Pattern, make sure the keywords of the article are set sufficiently accurate and rich.If the problem still exists, it is recommended to check the AnQiCMS backend log to see if there is any relevant error information.

Ask: Can I display multiple types of related articles on a single page? For example, some are in the same category and some are based on keywords?Answer: Absolutely. As shown in the practical example in the article, you can call it multiple timesarchiveListTag, set different parameters each time (for example, one time setcategoryId, and another time settype="related"andlike="keywords"), to obtain and display the list of associated articles under different logic.This combination of use can provide users with more diverse recommendation content, further improving the efficiency of content discovery and user satisfaction.

Ask: Does AnQiCMS automatically exclude the article currently being read to avoid its repetition in the related article list?Answer: AnQiCMS'archiveListTags do not automatically exclude the current article when retrieving related content. As an operations person, you need to manually add logic in the template code to exclude the current article. This is usually done byforAdd conditional judgment inside the loop, for example{% if item.Id != currentArticleId %}of whichcurrentArticleIdIs the one you get througharchiveDetailThe current article ID obtained by the tag. This processing ensures the smoothness of user experience and avoids unnecessary repetition.

Related articles

How to automatically convert URLs and email addresses in the text content into clickable links?

Today, with the increasing richness and frequent updates of digital content, website operators not only need to pay attention to the quality of the content, but also to the way it is presented and the user interaction experience.When we publish articles, product descriptions, or any text information on AnQiCMS (AnQiCMS), we often include some URL links and email addresses pointing to external resources or contact information.If this information is only displayed in plain text, users will have to manually copy and paste, which undoubtedly increases the complexity of the operation and reduces the user experience.

2025-11-06

How to wrap long text content automatically at a specified length?

As an experienced CMS website operation personnel, I fully understand the core status of content in website operation.High-quality content not only requires careful creation, but also needs to be presented in **a way** to ensure the efficiency of user experience and information delivery.How to effectively handle automatic line breaks for long text content is the key to improving the readability and aesthetics of the page.The AnQi CMS maintains the integrity of content storage, but on the front-end display level, it provides flexible automatic line break solutions through its powerful template engine and rich filters.

2025-11-06

How to format a floating-point number to display with a specified number of decimal places?

As an experienced CMS website operation person in the security industry, I know that both the accuracy and beauty of data are equally important in content display.Especially for floating-point numbers, how to format them to display with a specified number of decimal places is a key element in improving user experience and ensuring clarity of information.The powerful template engine of AnQi CMS provides flexible filter (filters) functions, allowing us to easily achieve this requirement.

2025-11-06

How to get the actual length of a string, array, or key-value pair?

As an experienced website operator who is well-versed in AnQi CMS, I fully understand the importance of accurately obtaining data length in content management and template design.In order to optimize the display layout, implement conditional judgments, or ensure the integrity of the content, having a clear understanding and operational ability of the actual length of strings, arrays (or slices in Go language), and key-value pairs (maps or structures in Go language) is crucial for improving website user experience and operational efficiency.

2025-11-06

How to directly call the built-in methods of Go struct in the template?

As a professional who has been deeply engaged in the content operation of Anqi CMS for a long time, I know that the template plays a core role in the presentation of website content.A highly efficient and flexible template system that can greatly enhance the efficiency and richness of content publishing.AnQi CMS, with its powerful backend based on Go language, provides template developers with the ability to directly interact with the underlying data structure, one very practical feature being the ability to directly call built-in methods defined in Go structs in the template.

2025-11-06

How to unify the overall layout and structure of the website through the template inheritance mechanism?

As an experienced CMS website operation person, I know the importance of an efficient and unified template system for website operation.AnQi CMS, with its high-performance architecture based on the Go language and flexible template system, provides us with powerful tools to ensure the consistency of content display, the unity of brand image, and greatly improve the efficiency of content management and publication.The importance of unified website layout and structure Maintaining consistency in the overall layout and structure of a website is crucial for attracting and retaining users in website operations.a mess

2025-11-06

How to create reusable code snippets (macro functions) in templates?

As an experienced AnQiCMS website operator, I know that efficiency and consistency are very important in daily content management.Especially in template design and content publishing, if code can be effectively reused, it can not only greatly improve work efficiency, but also ensure the consistency of website visual and functional integrity.Today, I will discuss with everyone how to create and utilize reusable code snippets, also known as macro functions, which are one of the key tools for our efficient operation.### Template code reuse

2025-11-06

How to implement batch replacement of keywords or links in website article content?

As a long-term深耕 website operator who has a deep understanding of AnQiCMS (AnQiCMS), I know that content is the lifeline of the website, and efficient content management is the key to success.In daily operations, we often encounter the need to update keywords or links in a large number of articles on the website, which may be due to brand strategy adjustments, SEO optimization needs, changes in links from external cooperative partners, or even legal and regulatory requirements.Facing thousands of articles, manually modifying one by one is undoubtedly a nightmare that consumes time and effort.It's lucky that

2025-11-06