In website content operation, providing users with relevant article recommendations is an important strategy to enhance user experience, extend visit duration, and optimize content discovery. The document list interface of AnqiCMS is (archive/listProvided a very convenient feature, by settingtype=relatedparameters, you can easily achieve this goal.
Understandingtype=relatedmode
After a user finishes browsing a document (article, product, etc.), they usually hope to find more resources that are thematically similar and complementary to the current content. AnqiCMS'sarchive/listThe interface is designed for this. It allows you to request a list of other related documents from the system using a simple parameter.
The calling address of this function is:{域名地址}/api/archive/list
The request method is:GET
It is based on the coordination of the following parameters:
type=relatedThis is the most critical parameter, it clearly tells the AnqiCMS interface that you expect to get recommended content related to a specific document, rather than ordinary list pagination or the entire list.id:Whentypeis set torelatedat that time, thisidThe parameter isnecessaryit specifies the one you want to get "related articles" ofthe ID of the current document. AnqiCMS will match other related content based on this ID intelligently.moduleIdIt is not required, but it is strongly recommended that you specify. If your website has multiple document models (such as article models, product models, etc.), clearlymoduleIdEnsure that AnqiCMS only searches for related articles within the model of the current document, avoiding recommendations of documents across models that may not be relevant.categoryId: It is also an optional parameter, but it is very helpful in enhancing relevance. By specifying the current document'scategoryIdYou can limit the search range of related articles to the same category, which usually provides more accurate recommendations.limit: Used to control the number of relevant articles returned, for example, setlimit=5The interface will return up to 5 related articles.order: You can use this parameter to sort the related articles. For example,order=views descCan retrieve the related articles with the highest view count under the current document category, ororder=created_time descto display the latest released related articles.
How to get the practical steps of related articles
Assuming you are developing an article detail page, you need to recommend 5 articles related to the current article at the bottom of this page.
Step 1: Get the ID of the current article
First, you need to know the ID of the article the current user is browsing. This ID is usually obtained when you through the interface to get the article details. For example, if the ID of the current article isarchive/detailis123.
The second step: Build the API request
Next, you can construct a request forarchive/lista GET request to the interface with the necessary parameters.
A typical request URL might look like this:
GET {域名地址}/api/archive/list?id=123&type=related&moduleId=1&categoryId=45&limit=5&order=views%20desc
id=123: The current article's ID is 123.type=related: Specify to get related articles.moduleId=1: The current article belongs to the article model with ID 1.categoryId=45: Assuming the current article belongs to category ID 45. This helps to limit the recommended articles to the same category.limit=5: Limit to returning only 5 related articles.order=views%20descSort by views from high to low, recommend popular related articles.
Step 3: Process the returned data
AnqiCMS will return a JSON formatted data, whichdataThe field is an array that contains detailed information about related articles, for example:
{
"code": 0,
"data": [
{
"id": 124,
"title": "相关文章标题一",
"url_token": "related-article-one",
"description": "这是相关文章一的简介...",
"logo": "https://...",
"link": "https://yourdomain.com/article/124.html"
},
{
"id": 125,
"title": "相关文章标题二",
"url_token": "related-article-two",
"description": "这是相关文章二的简介...",
"logo": "https://...",
"link": "https://yourdomain.com/article/125.html"
}
// ... 更多相关文章
],
"msg": ""
}
You can traversedataArray, extract the title, link, thumbnail information of each article, and display it on the page.
optimize and **practice
- Improve relevance accuracy:AnqiCMS will judge the relevance of the current article based on the classification, keywords and other information. Therefore, be sure tofill in the classification and keywords accuratelyThis will directly affect
type=relatedThe recommended effect of the model. - Control the number of displayed items: The number of relevant articles on the page should not be too many, usually 5-10 articles are a suitable range, which can be achieved through
limitParameters for control. Too many recommendations may distract the user's attention. - Diversified sorting: Besides the default sorting, try using
orderParameters, such as sorting byviews desc(Browsing views in descending order) Recommend popular articles or sort bycreated_time desc(Published time in descending order) Recommend the latest articles to increase the diversity of recommendations. - Caching mechanism: For frequently visited article pages, the data of related article lists can be considered to be cached on the front-end or server-side to reduce API requests during each page load, thereby improving website performance.
By mastering the use oftype=relatedPattern, you can bring stronger internal link structure and better user browsing experience to websites driven by AnqiCMS, making your content more discoverable and usable.
Frequently Asked Questions (FAQ)
Q1: Why did I set uptype=relatedBut the interface returnsdataThe array is empty?A1: There are several reasons why an empty array is returned. First, please check if you have correctly passed the parameters of the current article'sidThis istype=relatedthe unique basis for pattern relevance matching. IfidInvalid or missing, the interface will not work. Secondly, AnqiCMS will try to match according to the classification, keywords and other information of the article. If the current article lacks these related information, or there are not enough relevant articles in the database to recommend, it may also lead to an empty list being returned.You can try to add more relevant tags and keywords to the article and ensure that there is enough other content associated with it.
Q2:type=relatedHow is the relevance of articles judged? Can I customize the relevance matching algorithm?A2: AnqiCMS internally usually matches based on common categories, tags, keywords, and other metadata of articles to intelligently identify related content.This is a built-in logic, designed to provide out-of-the-box related recommendation features.Currently, AnqiCMS's API interface does not provide an option to directly customize the relevance matching algorithm.But you can indirectly affect and optimize the recommendation effect of related articles by carefully planning the classification system of the articles, accurately setting the tags and keywords, and adding more contextual information to the content of the articles themselves.
Q3: If I only want to retrieve relevant articles in a specific category, what should I do?A3: If you want to limit the scope of related articles to a specific category, in addition to settingtype=relatedand the current article'sidyou should also providecategoryIdThe parameter should be set to the category ID of the current article. For example: `id=123&type=related&categoryId=