How to display a list of recommended articles related to the current article?

In website operation, recommending relevant articles to readers is an important strategy to improve user experience, extend user stay time, and optimize SEO.After a reader finishes reading an article, if they can immediately see recommendations highly relevant to the current content, it will undoubtedly greatly increase their interest in continuing to explore the website.AnQi CMS understands this need and provides powerful and flexible functions to help users easily achieve this goal.

The 'Related Documents' feature in AnqiCMS

One of the core strengths of AnQi CMS lies in its powerful content management and template tag system. To display a list of recommended articles related to the current article, we mainly usearchiveListThis template tag.archiveListTags can not only be used to display regular article lists, category article lists, but also especially support displaying "related documents", which is exactly the core function we need.

Core tags:archiveListApplication

archiveListThe tag is used to retrieve article data from the database and display it in a list. It has rich parameters that can help us precisely control the filtering, sorting, and display of articles.

Basic usage: Display the recommended list related to the current article

Of Security CMSarchiveListTags are combinedtype="related"After the parameters, it can intelligently recognize the article being displayed on the current page and automatically fromin the same categoryFind similar or adjacent articles to the current article as recommendations.

This is an example of the template code for implementing this function:

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

Code analysis:

  • {% archiveList archives with type="related" limit="5" %}This is the core tag.
    • archives: The variable name you define for the recommended article list, you can use it in{% for %}Use it in the loop.
    • type="related"This parameter tells AnQi CMS that we want to get articles related to the current article.The AnQi CMS will automatically match the current article based on the category, ID, and other information.
    • limit="5": Limit the number of recommended articles to 5. You can adjust this number based on the page layout and requirements.
  • {% for item in archives %}: Loop through the list of recommended articles obtained.
    • item.Link: The link address of the recommended articles.
    • item.Title:Recommended article title.
    • item.Thumb:Recommended article thumbnail (if any). The thumbnail uploaded during document editing in the background will be displayed here.
    • stampToDate(item.CreatedTime, "2006-01-02"): Use.stampToDateThe filter formats the creation timestamp of the article into the date format of "Year-Month-Day".
  • {% empty %}: This is a very practical tag. IfarchiveListNo matching recommended articles were found.{% empty %}and{% endfor %}The content between the brackets will be displayed, avoiding blank pages or error prompts, thus improving user experience.

More accurate recommendation strategy: based on keywords or manual association.

In addition to automatic recommendations based on categories,archiveListtags also allow you to refine the definition of “relevant” throughlikeparameters, further defining the “relevant” concept.likeparameters need to be used withtype="related"together.

  1. Based on keyword recommendation (like="keywords")If you want to match the keywords of the article more precisely, you canarchiveListadd alike="keywords"Parameters. Anqi CMS will search for other articles containing the same keywords set in the current article under the same model.

    <div class="related-articles-by-keywords">
        <h3>根据关键词推荐</h3>
        <ul>
            {% archiveList keywordArchives with type="related" like="keywords" limit="3" %}
                {% for item in keywordArchives %}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
                {% empty %}
                <li>暂无根据关键词推荐的文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>
    </div>
    
  2. Based on manual association recommendation (like="relation")In the Anqi CMS backend document editing interface, you can manually link other articles as recommendations.This method is the most accurate because it is completely controlled by the operator.To call these manually associated articles, you can uselike="relation"Parameter.

    <div class="related-articles-manual">
        <h3>编辑精选推荐</h3>
        <ul>
            {% archiveList manualArchives with type="related" like="relation" limit="4" %}
                {% for item in manualArchives %}
                <li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
                {% empty %}
                <li>暂无编辑精选推荐文章。</li>
                {% endfor %}
            {% endarchiveList %}
        </ul>
    </div>
    

Flexibly display recommended article information

In the above examples, we mainly displayed the article title, link, thumbnail, and publish time. In fact,itemVariables provide more field information for articles, and you can choose and combine them according to your design needs:

  • item.Description: The article's introduction or abstract. If the content is long, it can be combined withtruncatecharsFiltered by the filter, for example{{ item.Description|truncatechars:80 }}.
  • item.Views: The number of views of the article, which can show the popularity of the article.
  • item.CategoryId: The ID of the category to which the article belongs, combinedcategoryDetailTags can obtain the name and link of the category.
  • item.Logo: The article cover main image (usually a larger image).
  • item.Images: The article cover group image, this is an array, you can display multiple images by looping.

Example: Combine summary and views.

<div class="related-articles-full">
    <h3>更多相关推荐</h3>
    <ul>
        {% archiveList moreArchives with type="related" limit="6" %}
            {% for item in moreArchives %}
            <li>
                <a href="{{ item.Link }}">
                    <h4 class="related-title">{{ item.Title }}</h4>
                    {% if item.Description %}
                        <p class="related-description">{{ item.Description|truncatechars:120 }}</p>
                    {% endif %}
                    <div class="related-meta">
                        <span>发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
                        <span>阅读量:{{ item.Views }}</span>
                    </div>
                </a>
            </li>
            {% empty %}
            <li>暂无更多相关推荐。</li>
            {% endfor %}
        {% endarchiveList %}
    </ul>
</div>

Summary

Utilizing the powerful AnQi CMSarchiveListTagging and flexible parameter settings allow you to easily display a diverse list of recommended articles on the current article page.Whether it is an intelligent recommendation based on article classification, or an accurate match based on keywords, or even high-quality content manually associated by the operator, Anqi CMS can provide a simple and efficient implementation method.These features not only help to enhance the content depth and user engagement of the website, but also play a positive role in search engine optimization.


Frequently Asked Questions (FAQ)

1. Why is my recommended article list not displaying any content?

  • Check the article properties:Make sure the current article is set to a category.type="related"The pattern mainly relies on the classification information of the article to find related content.
  • Number of contents:Ensure your website has enough content, especially the number of articles in the same category. If there are too few articles, it may not be possible to find suitable recommendations.
  • Keyword/related settings:If you have usedlike="keywords"orlike="relation"Please enter the parameters,