In website operation, the 'related articles' list below the article detail page is an important feature for improving user experience, increasing page views (PV), and extending the time users spend on the site.It can guide users to discover more interesting content, thereby enhancing the overall stickiness of the website and also having a positive effect on Search Engine Optimization (SEO).To implement this function in AnQi CMS, it benefits from its flexible template system and powerful tag functions, making the whole process both intuitive and efficient.
1. Understanding the call mechanism of 'related articles'
The template tags of Anqi CMS are the core of implementing various functions. To display related articles, we mainly usearchiveListThis tag. This tag can be used to display a list of ordinary articles, and it also specially providestype="related"parameters to intelligently filter out recommended content related to the current article.
Whentypeparameter settings"related"The system will automatically search for other articles with similar content or close in time within the category of the current article's ID. You can further through.limitThe parameter to control the number of displayed articles, for example,limit="5"means displaying 5 related articles.
Second, determine the location of the template file.
Firstly, you need to find the corresponding template file for the article detail page. According to the template design conventions of AnQi CMS, the default template for the article detail page is usually located{模型table}/detail.htmlFor example, if your article belongs to the "article model", it is usually inarchive/detail.html。If you have customized a template for a specific article or category, please make the operation in the corresponding custom template file.
3. Write template code to display the list of related articles
After finding the article detail page template file, you can add the following code snippet at an appropriate position on the page (usually below the article content, above or below comments) to call and display the related article list:
{% archiveList archives with type="related" limit="5" %}
{% if archives %}
<div class="related-articles-section">
<h3>相关推荐</h3>
<ul class="related-articles-list">
{% for item in archives %}
<li class="related-article-item">
<a href="{{item.Link}}" title="{{item.Title}}">
{% if item.Thumb %}
<img src="{{item.Thumb}}" alt="{{item.Title}}" class="related-article-thumb">
{% endif %}
<span class="related-article-title">{{item.Title}}</span>
</a>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endarchiveList %}
Code analysis:
{% archiveList archives with type="related" limit="5" %}:This is the core tag, it tells the security CMS to find articles related to the current article and store the results in a namearchives.limit="5"The number of displayed articles is limited to 5.{% if archives %}This is a conditional judgment to ensure that the entire 'Related Recommendations' block is displayed only when relevant articles are found, to avoid an empty title on the page.<h3>相关推荐</h3>:This is the title of the related article list, you can customize it according to the website style.{% for item in archives %}:If related articles are found, this will iterate througharchiveseach article in the variable.{{item.Link}}:输出当前循环文章的链接。{{item.Title}}:输出当前循环文章的标题。{% if item.Thumb %}:检查文章是否有缩略图。<img src="{{item.Thumb}}" alt="{{item.Title}}">:如果文章有缩略图,则显示。{% endfor %}/{% endif %}/{% endarchiveList %}:分别对应。forlooping,ifJudgment andarchiveListThe end mark of a tag.
You can adjust as needed.limitThe value, or add more article fields (such as){{item.Description}}Display the summary,{{stampToDate(item.CreatedTime, "2006-01-02")}}Display the publish date, etc.), to enrich the display of your related article list.
Four, select the matching strategy for related articles (Advanced))
archiveListTags intype="related"Based on that, it also provideslikeParameters, allowing you to control the matching logic of related articles more accurately:
Matching based on keywords (
like="keywords")If you want the article recommendations to be more focused on the similarity of content themes, you can use the keywords of the article. When you publish an article in the background, you will fill in the keywords for the article. Uselike="keywords"Parameter, Safe CMS will search for other articles with high overlap with the current article keywords for recommendation.Modified code example:{% archiveList archives with type="related" like="keywords" limit="5" %} {# ... 相同的for循环和展示逻辑 ... #} {% endarchiveList %}Prerequisite:Ensure that your article has relevant keywords filled in the "Document Keywords" field in the background.This can be found and set on the "Content Management" -> "Publish Document" or "Edit Document" interface.
Based on manual association matching from the background,
like="relation")In some cases, you may want to manually specify the relevance between certain articles, such as serial articles or thematic reports.AutoCMS allows you to set 'related documents' in the background document editing interface.like="relation"Parameters, the system will only display the articles you manually associate.Modified code example:{% archiveList archives with type="related" like="relation" limit="5" %} {# ... 相同的for循环和展示逻辑 ... #} {% endarchiveList %}Prerequisite:You need to manually associate other articles when editing articles in the background. For specific operations, please refer to the document or the 'Other Parameters' section of the background interface.
By flexibly using these parameters, you can tailor the most relevant article recommendation list that meets user needs according to the operation strategy and content features of the website, effectively enhancing the interactivity and content value of the website.
Frequently Asked Questions (FAQ)
Question: Why didn't the related articles show up at the bottom of the page even though I added the code for them?Answer: There may be several reasons.First, please check that your template code is correct without any errors, including the start and end tags.Next, ensure that there is enough content on your website, and that this content is somewhat related to each other (for example, in the same category, with the same keywords, or manually associated), because if there are no matching articles, the list will naturally be empty.
limitIs the parameter set to 0 or a negative number, which can also cause the articles not to be displayed?Q:
type="related"andlike="keywords"/like="relation"What are the differences? Which method should I choose?Answer:type="related"is a basic command that tells the system to look for relevant articles. By default, it will perform a broad match based on the current article's category and publication time, etc. Whilelike="keywords"andlike="relation"is a reference totype="related"Match logic is further refined:like="keywords"Will prioritize matching based on the keywords of the article, with a greater emphasis on the similarity of the content theme.If you want users to see articles on the same topic as the current one but possibly from different categories, this option is very useful.like="relation"It will only display other articles that you manually associate when editing articles in the background.This is suitable for scenarios where you have clear series articles, thematic recommendations, or need manual intervention for recommendation lists. Choose which method depends on your specific needs.like="keywords". If you need to precisely control the recommended content, you can choose:like="relation".
Question: Can I display the publication date or summary of the article in the list of related articles?答:Of course you can. In
{% for item in archives %}the loop, besides{{item.Title}}and{{item.Link}}, you can also use otheritemfields to enrich the display content. For example, to display the publication date, you can use{{stampToDate(item.CreatedTime, "2006-01-02")}}To display the article summary, you can use{{item.Description}}. Just add these variables to your<li>tags, and combine them with HTML and CSS for layout.