How to display related article recommendations at the bottom of the AnQiCMS article detail page?

Calendar 👁️ 71

In AnQiCMS, adding a related articles recommendation feature to the article detail page can not only effectively increase the user's stay time on the website, guide them to discover more interesting content, but also have a positive effect on the website's SEO performance.It is not difficult to achieve this function with the flexible and powerful template tag system provided by AnQiCMS.

Understanding the template structure of AnQiCMS

In AnQiCMS, the page layout and content display of the website are controlled by template files. The template files for the article detail page are usually located in your template directory, the specific path may be/template/{你的模板名称}/archive/detail.html. If you are using the default template, it is very likely thatdefault/archive/detail.html. Understanding this file is the first step in implementing related article recommendations, as all changes will be made here.

AnQiCMS's template language is similar to Django template engine, variables are passed through double curly braces{{变量名}}Display, while logical control (such as loops, conditional judgments) uses single curly braces and percent signs{% 标签 %}Define.

The core of realizing relevant article recommendation:archiveListTag

We need to use the AnQiCMS provided on the bottom of the article detail page to display related articlesarchiveListTemplate tag. This tag is specifically used to retrieve document lists and provides various parameters to meet different requirements, including the function of retrieving "related articles".

Add recommended content to the article detail page, you need to edit/template/{你的模板名称}/archive/detail.htmlfile. Find the end of the main content of the article, usually at{{archive.Content|safe}}After this code, or at any location where you wish to display recommended content.

The following are several common ways to implement article recommendation and their code examples:

1. Based on the "Automatic" related recommendations of the current article

This is the simplest and most commonly used method. AnQiCMS, by default, when you usetype="related"When a parameter is specified, it will intelligently retrieve the closest other document to the current article, which is usually an article in the same category or with a similar publication time.

<div class="related-articles">
    <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}}">
                {% endif %}
                <span class="article-title">{{item.Title}}</span>
                <span class="article-date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            </a>
        </li>
        {% empty %}
        <li>暂无相关文章推荐。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

Code explanation:

  • <div class="related-articles">...</div>This is a container, you can add styles according to your website design.
  • {% archiveList archives with type="related" limit="5" %}This is the core tag.
    • archivesDefine a variable name to store the list of articles obtained.
    • type="related": Indicate the system to retrieve relevant articles.
    • limit="5": Limit the number of recommended articles to 5.
  • {% for item in archives %}...{% endfor %}: Loop through each article retrieved.
    • item: Represents the current article object in each loop.
    • {{item.Link}}Get the article link.
    • {{item.Title}}Get the article title.
    • {% if item.Thumb %}<img src="{{item.Thumb}}" alt="{{item.Title}}">{% endif %}Check if the article has a thumbnail, and display it if it does.item.ThumbIt will automatically provide the thumbnail path.
    • {{stampToDate(item.CreatedTime, "2006-01-02")}}: Format the article's publish timestamp to the "year-month-day" format.
  • {% empty %}<li>暂无相关文章推荐。</li>{% endempty %}: This is a very practical structure, whenarchiveListNo articles are retrieved, it will displayemptyBlock content, not blank.

2. Relevant recommendations based on the article's 'keywords'

If you want the recommended articles to be highly relevant to the current article's keywords (Tag), you can uselike="keywords"The parameter indicates that AnQiCMS will search for other related articles based on the first keyword of the current article.

<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}}" title="{{item.Title}}">
                <span class="article-title">{{item.Title}}</span>
                <span class="article-date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            </a>
        </li>
        {% empty %}
        <li>暂无基于关键词的相关推荐。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

This example is similar to the first, but it is in thearchiveListtag added.like="keywords"Parameters, AnQiCMS will automatically handle the matching logic.

3. Based on the relevant recommendations of 'Manual association in the background'

AnQiCMS also supports manually associating other articles in the background article editing interface. If you have already set up these manual associations in the background and want to display them, you can uselike="relation"Parameter.

<div class="related-articles-by-relation">
    <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="article-title">{{item.Title}}</span>
                <span class="article-date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            </a>
        </li>
        {% empty %}
        <li>暂无手动关联推荐。</li>
        {% endfor %}
    {% endarchiveList %}
    </ul>
</div>

Similarly, just modifylikethe parameters. Please note that if the article has not been manually associated, or if the selected 'related' logic does not match any articles,{% empty %}The block prompt will take effect.

Summary

By using the above methods, you can flexibly implement related article recommendation functions at the bottom of the AnQiCMS article detail page according to your own content strategy and needs.Choose the recommendation logic that best suits your website, paste the code snippet in the appropriate position of the article detail page template, save the file, and refresh the website page to see the effect.Remember to add appropriate CSS styles to the recommended block to keep it consistent with the overall design style of your website and provide a better user experience.


Frequently Asked Questions (FAQ)

**1. How do I recommend articles not in the current category, or only recommend certain specific categories?

Related articles

How to implement website in-site search and display article search results in AnQiCMS?

In website operation, the in-site search function plays a crucial role.It can not only help visitors find the information they need quickly, improve user experience, but also through the analysis of search data to understand user needs, optimize content strategy.The AnQi CMS is an efficient content management system that provides a set of intuitive and powerful mechanisms to implement site search and flexibly display search results.The on-site search function of Anqi CMS is designed to be very practical.

2025-11-08

How to display the associated Tag tag list on the AnQiCMS article detail page?

In website content operation, tags are important tools for connecting related content, enhancing user experience, and optimizing search engine rankings.AnQiCMS as an efficient content management system, naturally supports the association function between articles and tags.How can we clearly display these associated tags on each article's detail page to allow readers to quickly find more interesting content?This article will guide you in easily displaying the tag list on the article detail page of AnQiCMS.

2025-11-08

How to correctly render Markdown formatted article content in AnQi CMS and display it?

Today, with the increasing efficiency in content creation, Markdown is favored by content creators for its concise syntax and focus on the content itself.AnQi CMS understands this trend and provides powerful features that allow you to easily convert Markdown-formatted article content into exquisite HTML pages and support richer display effects, such as mathematical formulas and flowcharts.

2025-11-08

How to configure the lazy loading effect of images in the AnQiCMS article content?

In AnQiCMS, optimizing website loading speed is a key step to improving user experience and search engine rankings.When the article content contains a large number of images, these images will significantly increase the page loading time.Image lazy loading (Lazy Loading) is an efficient way to solve this problem, it can prevent images from loading until they enter the user's field of vision, thereby speeding up the initial rendering speed of the page.AnQiCMS as a content management system focusing on performance and SEO provides flexible support for lazy loading images in article content.You can configure the template simply

2025-11-08

How to build multi-condition filtering function for article list and display results in AnQiCMS?

In website operation, providing flexible multi-condition filtering functions for article lists can greatly enhance user experience and the discoverability of content.AnQiCMS (AnQiCMS) leverages its powerful content model and rich template tags to make building such features intuitive and efficient.Below, we will delve into how to step by step implement multi-condition filtering and display results of article lists in AnQiCMS.

2025-11-08

How to automatically generate and display a table of contents (TOC) on the AnQiCMS article content page?

In AnQiCMS, automatically generating and displaying the table of contents (TOC) for article content pages not only significantly enhances the user reading experience but also helps search engines better understand the article structure, thereby having a positive impact on SEO.With the powerful and flexible template system of AnQiCMS, it is simpler to achieve this function than you imagine.How does AnQiCMS support automatic directory generation?

2025-11-08

How to format the display of the publication and update time of articles in the AnQiCMS template?

In Anqi CMS website templates, displaying the publication and update time of articles is a key factor in improving user experience and content management efficiency.Clearly present this time information, which not only helps visitors quickly understand the timeliness of the content, but also assists search engines in better crawling and indexing.AnQiCMS provides a powerful and flexible template tag that allows you to format timestamps into various easily readable date and time formats as needed.### Core Mechanism: `stampToDate` tag The template system of Anqi CMS is built-in with a named

2025-11-08

How to display the reading views of articles on the AnQiCMS article list or detail page?

In website content operation, the number of article views is an important indicator, which helps us understand the popularity of the content and the user's interests.AnQiCMS provides a convenient way for you to visually display this data on the article list page or detail page. ### Understanding AnQiCMS's Page View Mechanism AnQiCMS is a comprehensive content management system that comes with a built-in mechanism for automatically recording article page views.

2025-11-08