How can AnQi CMS display a list of recommended articles related to the current article content?

Calendar 👁️ 71

In website operation, providing a list of recommended articles related to the current content is an important strategy to enhance user experience, prolong user stay time, and optimize internal website links.AnQiCMS (AnQiCMS) fully understands this and provides flexible and powerful features to help you easily achieve this goal.

Core feature analysis: Related document tagsarchiveList

To display a list of recommended articles related to the current article content in AnQi CMS, you will mainly use a very key template tag -archiveList. This tag can not only be used to obtain a list of regular articles or paginated lists, but also includes dedicated logic for handling 'related articles' recommendations.

When you are using the article detail pagearchiveListthe tag and use it.typethe parameter to"related"At that time, the system will intelligently recommend related articles based on the content of the current article. This greatly simplifies the complexity of template development, allowing you to write complex query logic.

The basic calling method can be like this:

{% archiveList relatedArchives with type="related" limit="5" %}
    {# ... 这里将显示相关文章列表 ... #}
{% endarchiveList %}

Here, relatedArchivesIt is the variable name you define for the recommended article list,type="related"tells the system to retrieve related articles,limit="5"and controls the number of recommended articles.

Understand the definition of 'related': various recommendation logic

When evaluating 'relevance', AnQi CMS does not follow a single fixed pattern. It provides multiple logic to help you define the association between articles more accurately.

first, Default association logicThis is based on the current article's category. The system will try to find other articles with similar publication times or content associations within the same category for recommendation.This means that reasonably planning your article classification structure is the basis for improving the default recommendation accuracy.

Secondly, you can also uselikeParameters to further refine the recommendation logic:

  • Keyword-based recommendation (like="keywords"): If you want the recommended articles to be more precise around a certain topic, you can use the keywords of the articles. When settinglike="keywords"At that time, the system will match other articles' keywords based on the current article's set keywords, thereby recommending articles with closer themes.This requires you to carefully fill in the keywords of the article when publishing (you can manually enter or select from the keyword library when editing the article in the background content management).At the same time, by using the 'Document Tag' feature to label the article appropriately, it can also indirectly enhance the matching effect of keywords.

  • Manually associated recommendation (like="relation")For some articles where you need to specify the association explicitly, such as the next article in a series of tutorials or an extended reading of a product introduction, Anqi CMS provides the function to manually set associated articles. When you arearchiveListSet in the labellike="relation"At that time, the system will only display those articles that you manually associate in the current article editing interface.This provides you with极高的flexibility, ensuring that certain articles are always displayed in the recommended list.

Code实战:In the template add the recommended article list

Next, let's look at a complete example that demonstrates how to add a recommended article list with thumbnails, titles, and summaries in the article detail page template. This example combineslike="keywords"The recommendation logic to provide more content-related recommendations.

Assuming your article detail page template file (for example)archive/detail.htmlIt is necessary to add a recommended article area in the following section:

{# 假设这是文章详情页模板的一部分 #}

<article class="article-detail">
    {# ... 这里是当前文章的标题、内容等详情 ... #}
</article>

{# 推荐阅读区域 #}
<div class="related-articles">
    <h3>推荐阅读</h3>
    {% archiveList relatedArchives with type="related" like="keywords" limit="5" %}
        {# 检查是否有推荐文章返回 #}
        {% if relatedArchives %}
            <ul>
                {% for item in relatedArchives %}
                    <li>
                        <a href="{{ item.Link }}" title="{{ item.Title }}">
                            {# 如果文章有缩略图,则显示 #}
                            {% if item.Thumb %}
                                <img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="related-thumb">
                            {% else %}
                                {# 或者显示一个默认的占位图 #}
                                <img src="/static/images/default-thumb.jpg" alt="默认缩略图" class="related-thumb">
                            {% endif %}
                            <span class="related-title">{{ item.Title }}</span>
                            {# 截取文章描述,保持列表整洁 #}
                            <p class="related-description">{{ item.Description|truncatechars:80 }}</p>
                        </a>
                    </li>
                {% endfor %}
            </ul>
        {% else %}
            {# 没有找到相关推荐文章时的提示 #}
            <p>暂无相关推荐文章,敬请期待更多精彩内容!</p>
        {% endif %}
    {% endarchiveList %}
</div>

{# 您可能还需要一些CSS样式来美化这个推荐列表,例如: #}
<style>
    .related-articles {
        margin-top: 40px;
        padding: 20px;
        border-top: 1px solid #eee;
        background-color: #f9f9f9;
    }
    .related-articles h3 {
        font-size: 20px;
        color: #333;
        margin-bottom: 20px;
        text-align: center;
    }
    .related-articles ul {
        list-style: none;
        padding: 0;
        display: flex;
        flex-wrap: wrap;
        gap: 20px; /* 文章间距 */
    }
    .related-articles li {
        flex: 1 1 calc(33.333% - 20px); /* 三列布局,减去间距 */
        min-width: 280px; /* 最小宽度 */
        background-color: #fff;
        border: 1px solid #ddd;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    }
    .related-articles li a {
        text-decoration: none;
        color: #333;
        display: block;
        padding: 15px;
        height: 100%;
        box-sizing: border-box;
    }
    .related-articles .related-thumb {
        width: 100%;
        height: 150px;
        object-fit: cover;
        border-radius: 4px;
        margin-bottom: 10px;
    }
    .related-articles .related-title {
        font-size: 16px;
        font-weight: bold;
        display: block;
        margin-bottom: 5px;
        line-height: 1.4;
        height: 45px; /* 标题固定高度 */
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    .related-articles .related-description {
        font-size: 13px;
        color: #666;
        line-height: 1.5;
        height: 60px; /* 描述固定高度 */
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
    }
    .related-articles p {
        text-align: center;
        color: #666;
    }
</style>

In this code block:

  • We usearchiveListThe tag obtained recommended articles and specifiedtype="related"andlike="keywords"and limited the display5articles.
  • By{% if relatedArchives %}Determine if there are articles returned to avoid displaying an empty list in an unattractive way.
  • Loop throughrelatedArchivesin each item (item), and display its title (item.Title) and link (item.Link) and thumbnail (item.Thumb).
  • useditem.Description|truncatechars:80A filter to extract the article summary, ensuring the layout of the recommendation list is neat.
  • If the article does not have a thumbnail, we provide the path to a default placeholder image to ensure the display effect.
  • The accompanying CSS style code can help you quickly build a responsive and beautiful recommendation article layout.

Optimization and personalization

Related articles

How to add captcha display to the comment feature of Anqi CMS to enhance security?

Maintaining a healthy, interactive website comment section is an indispensable part of content operation.However, comment sections often become hotbeds of spam and malicious attacks, which not only affects the quality of the website's content but also brings additional review burdens to website administrators.To effectively resist the interference of these automated programs, adding a captcha display to the comment feature of AnQi CMS is a simple and practical security enhancement measure.

2025-11-09

How to display a user's comment list in AnQi CMS and support multi-level replies and review status distinction?

The comment feature is an indispensable part of a website's content and user interaction, as it not only enlivens the atmosphere of the website but also provides valuable user feedback to the operator.Anq CMS fully understands its importance and provides a flexible and feature-rich comment system that allows website administrators to easily display and manage user comments, while also supporting multi-level replies and review status differentiation to ensure the interactivity and quality of website content. ### Overview of AnQi CMS Comment Function In AnQi CMS, to display the comment list of website content, it mainly relies on its powerful template tag system.

2025-11-09

How does the `urlize` filter in AnQi CMS automatically convert URLs in text to clickable links?

In the daily content creation and website operation, we often need to insert various links in articles, whether they point to external resources or refer to other content within the site.Manually converting these plain text URL addresses into clickable hyperlinks is undoubtedly a repetitive and error-prone task.Imagine if the amount of content on the website were massive, how much time and effort would it take to do this job?

2025-11-09

How to process front-end displayed data twice through the `filter` filter, such as truncating characters or formatting?

In Anqi CMS, data is stored in its original form, but we know that the data presented on the front end needs to be carefully crafted to present in a **pose to the users. At this point, the 'filter' in the template engine has become an indispensable tool in our hands.It can process data twice, whether it is accurately截取 long text, unify date format, or cleverly handle HTML content, it can easily cope with it, making your website content both professional and attractive.### Understanding the core role of "filter" Imagine one

2025-11-09

How to define and display temporary variables in Anqi CMS template for complex content layout?

In website content operation, we often encounter some scenes where we need to flexibly display data and dynamically adjust the layout.Sometimes listing information simply is not sufficient to meet complex design requirements, and at this point, if you can freely define and use some temporary variables in the template, it will greatly enhance our efficiency and the expressiveness of the template.AnQiCMS (AnQiCMS) with its powerful backend developed based on the Go language and the template engine syntax similar to Django, provides us with a flexible mechanism for defining and managing temporary variables, making it possible to create exquisite and complex content layouts.Define a temporary variable

2025-11-09

How does the `breadcrumb` tag in AnQi CMS generate and display flexible breadcrumb navigation?

When building a website, a clear and intuitive navigation system is crucial for user experience and search engine optimization (SEO).Breadcrumb navigation is a tool that can significantly improve website usability, clearly showing the user's current position on the site and providing convenient links to return to the previous level page.AnQi CMS knows this and provides a powerful and flexible `breadcrumb` tag.###

2025-11-09

How to display the language switch options and hreflang tags on Anqi CMS?

Today, providing multilingual support for websites has become a basic requirement for expanding the market and serving users in different regions.AnQiCMS (AnQiCMS) is fully aware of this need, integrating powerful multilingual functionality to allow website administrators to easily achieve content internationalization.This article will discuss in detail how to effectively display language switch options on AnQiCMS sites and correctly set the `hreflang` tag to optimize the internationalization recognition of search engines.Understanding AnQiCMS' multilingual capabilities AnQiCMS is an efficient

2025-11-09

How to implement the sorting display of article list by views (views desc) in AnQi CMS?

How to make a hot article on the website stand out quickly and attract more visitors' attention?This can effectively enhance user experience and is also the key to optimizing content strategy and guiding traffic.For users of AnQiCMS, it is a very practical and easy-to-operate feature to display article lists sorted by page views.The powerful template tag system of AnQi CMS allows you to easily display the most popular content on your website to users.### Core Feature Revelation: Utilize `archiveList`

2025-11-09