How to display a list of related articles based on the keywords of the article or custom associations?

In website content operation, providing users with a list of relevant articles can not only effectively extend the visitor's stay on the website and reduce the bounce rate, but also through guiding users to discover more interesting content, optimize the internal traffic path, and have a positive effect on SEO performance.AutoCMS (AutoCMS) knows this need and provides flexible and powerful functions, allowing us to easily display related article lists based on the keywords of the article or custom associations.

Understanding the association logic of Anqi CMS articles

At the initial design of AnQi CMS, the relevance between content was taken into consideration. It provides two main methods to help us build and display the relationships between articles: one is byKeywordsPerform automatic matching, the second is throughBackground manual settingEstablish precise custom association. These two methods have their respective focuses and can be flexibly selected according to actual operational needs.

Method one: Using keywords to achieve automatic association of articles

When we publish articles, we usually set keywords for the articles.These keywords not only help search engines understand the theme of the article, but are also an important basis for the CMS to automatically associate articles.The Anqi CMS can intelligently retrieve and recommend other articles similar to the current article based on the keywords of the article.

How to set article keywords:

In the background of AnQi CMS, when we enter the "Content Management" module and the "Publish Document,

Call related articles based on keywords in the template:

To display a list of articles automatically associated with keywords on the website page, we need to use the template provided by the Anqi CMS in the article detail page.archiveListLabel. This label has rich parameters that can help us accurately control the acquisition and display of content.

For example, to display 5 articles related to the current article's keywords at the bottom of the article detail page, we can write the template code like this:

{# 假设这里是文章详情页的模板代码 #}

<h3>相关推荐</h3>
<div>
    {% archiveList relatedByKeywords with type="related" like="keywords" limit="5" %}
        {% for item in relatedByKeywords %}
        <li>
            <a href="{{item.Link}}">{{item.Title}}</a>
            {# 如果需要显示简介或缩略图,可以进一步添加 #}
            {# <p>{{item.Description|truncatechars:50}}</p> #}
            {# {% if item.Thumb %}<img src="{{item.Thumb}}" alt="{{item.Title}}" />{% endif %} #}
        </li>
        {% empty %}
        <li>暂无相关推荐文章。</li>
        {% endfor %}
    {% endarchiveList %}
</div>

In this code block:

  • type="related"indicating the related articles we want to retrieve.
  • like="keywords"Explicitly tell the system to match relevant content based on the keywords of the article. AnQi CMS will search for the most relevant other articles based on the first keyword of the current article.
  • limit="5"Then the number of displayed articles is limited to 5.

This way, the system will intelligently recommend content based on the keywords of the article, saving the trouble of manual association, especially suitable for websites with a large amount of content and frequent updates.

Method two: Customize associated articles for precise recommendations

Sometimes, we may wish to control more precisely which articles are associated with each other, rather than relying entirely on the automatic matching of keywords.For example, the previous and next articles in a series, or specific product introductions and press releases manually associated with marketing activities.The AnQi CMS also supports this highly customizable association method.

How to set custom association:

When editing specific documents under the 'Content Management' section in the AnQi CMS backend, in addition to common fields such as keywords and descriptions, there will also be an option to set 'related documents'.Here, we can manually select and associate one or more articles that have a specific logical relationship with the current article.This manual association has the highest priority, ensuring that we accurately recommend content according to our operational strategy.

Call custom associated articles in the template:

Similar to keyword-based association, calling custom associated articles also requiresarchiveListtags, justlikethe parameters are different.

For example, to display 3 related articles manually set in the article detail page, the template code can be written as:

{# 假设这里是文章详情页的模板代码 #}

<h3>您可能也喜欢</h3>
<div>
    {% archiveList customRelations with type="related" like="relation" limit="3" %}
        {% for item in customRelations %}
        <li>
            <a href="{{item.Link}}">{{item.Title}}</a>
            {# 同样,可以根据需要添加更多字段 #}
        </li>
        {% empty %}
        <li>暂无特别推荐。</li>
        {% endfor %}
    {% endarchiveList %}
</div>

The key point here is:like="relation"This indicates that the security CMS only retrieves associated articles manually set in the background document editing interface. This provides great convenience for scenarios that require highly refined operations.

Flexible display and optimization

No matter which association method you choose,archiveListEach label returneditemit includes rich information about the article,Title(Title),Link(Link),Description[Summary],Thumb[Thumbnail],CreatedTime(Publish time) and others. We can freely combine these fields according to the design needs of the template to build a variety of related article list styles.

For example, if you want the list to display more richly, you can modify it in this way:

{# 这是一个更丰富的相关文章列表示例 #}
<h3>精选内容</h3>
<ul class="related-articles-list">
    {% archiveList featuredRelations with type="related" like="keywords" limit="4" %}
        {% for item in featuredRelations %}
        <li class="article-item">
            {% if item.Thumb %}
                <div class="article-thumb">
                    <a href="{{item.Link}}"><img src="{{item.Thumb}}" alt="{{item.Title}}"></a>
                </div>
            {% endif %}
            <div class="article-info">
                <h4><a href="{{item.Link}}">{{item.Title}}</a></h4>
                <p class="article-description">{{item.Description|truncatechars:80}}</p>
                <span class="article-date">{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
            </div>
        </li>
        {% empty %}
        <li class="no-results">暂时没有找到其他相关文章。</li>
        {% endfor %}
    {% endarchiveList %}
</ul>

Please note,item.Description|truncatechars:80This writing style uses the built-in filter of Anqi CMS, which can truncate the article summary to a specified character length and automatically add an ellipsis to ensure the neat layout of the page.stampToDateThe label makes it convenient to format timestamps into the date format we need.

Summary

The Anqi CMS allows us to conveniently display related article lists based on the keywords of the article or custom settings through its carefully designed template tags and flexible configuration options.Whether it is the keyword association of pursuing automation and mass content, or the need for fine-grained control and strong logicality in manual association, Anqi CMS can provide effective solutions to help us better organize content and improve the user experience and operational efficiency of the website.


Common Questions and Answers (FAQ)

If both keyword association and custom association are set, which method will be displayed first?

In AutoCMS, when you usetype="related"a tag to specifylike="relation", the system will prioritize displaying the custom associated articles that you manually set in the background. When you specifylike="keywords"时,则会根据文章的关键词进行自动匹配。这两个like参数是互斥的,您不能在同一个archiveListTags can be used at the same time to retrieve related articles from the same batch, but the two can be called separatelyarchiveListTags, respectively display two types of related article lists.

2. What will be displayed in the related articles list if the article does not have set keywords or custom associations?

If the article does not have any keywords set and is not manually associated with any other articles, and you are usingarchiveListtags that are not specifiedlike="keywords"orlike="relation", or if both of these match fail, thenarchiveListWithin the tags,{% empty %}The code block will be executed. Typically, we would place a hint inside, such as “No relevant recommendations” or “No other related articles found”, to avoid the page from being blank.{% empty %}Here, we can place a hint, for example “No relevant recommendations” or “No other related articles found”, to avoid the page from being blank.

3. 'How does it work to get relevant documents based on the first keyword in the document?'

When you uselike="keywords"Parameters, when, the security CMS will intelligently extract the current article's “document keywords” fieldfirstkeyword. Then, the system will search the entire content library based on this keyword