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 (archive/listProvided a very convenient function, through settingtype=relatedparameters, you can easily achieve this goal.

Understandingtype=relatedmode

When a user finishes browsing a document (article, product, etc.), they usually hope to find more information that is closely related to the current content theme and complements it. AnqiCMS'sarchive/listThe interface is designed for this. It allows you to request a list of other documents 'related' to the specified document by using a simple parameter.

The calling address of this feature is:{域名地址}/api/archive/list

The request method is:GET

It is based on the coordination of the following parameters:

  1. type=relatedThis is the most critical parameter, it explicitly 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.
  2. id: whentypesetrelatedauto,这个idParameter isautoauto。它指定了你想要获取“相关文章”的那个auto当前文档的ID。AnqiCMS will match other related content intelligently with this ID.
  3. moduleIdAlthough it is not required, it is strongly recommended that you specify. If your website has multiple document models (such as article models, product models, etc.), be clearmoduleIdIt can ensure that AnqiCMS only searches for related articles within the model of the current document, avoiding recommending documents across models that may not be relevant.
  4. categoryId:Same as optional parameter, but it is very helpful for improving relevance. By specifying the current document'scategoryIdYou can limit the search range of relevant articles to the same category, which usually provides more accurate recommendations.
  5. limitIt is used to control the number of relevant articles returned, for example, setlimit=5The interface will return up to 5 related articles.
  6. orderYou can use this parameter to sort the related articles. For example,order=views descCan get the most viewed related articles under the current document category, ororder=created_time descto display the latest related articles.

How to get the practical steps of related articles

Assuming you are developing a detailed article page, you need to recommend 5 related articles at the bottom of this page.

Step 1: Get the ID of the current article.

Firstly, you need to know the ID of the article that the current user is browsing. This ID is usually obtained when youarchive/detailget the details of the article through the interface. For example, if the ID of the current article is123.

第二步:Construct API Request

Next, you can construct a request forarchive/lista GET request for the interface, and include 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:Assume the current article ID is 123.
  • type=related:Specify to get related articles.
  • moduleId=1:Assume the current article belongs to the article model with ID 1.
  • categoryId=45:Assuming the current article belongs to the category with ID 45. This helps to limit the recommended articles to the same category.
  • limit=5:Limit to returning only 5 related articles.
  • order=views%20desc:Sort by views from high to low, recommend popular related articles.

Third step: Handle returned data

AnqiCMS will return a JSON formatted data, wheredataThe field is an array that contains detailed information about related articles, such as:

{
  "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 iterate overdataArray, extract the title, link, thumbnail and other information of each article, and display it on the page.

Optimization and **Practice

  • Improve the accuracy of relevance:AnqiCMS will judge the relevance based on the current article's category, keywords and other information. Therefore, be sure tofill in the category and keywords accuratelyThis will directly affecttype=relatedThe recommended effect of the pattern.
  • Control the number of displayed items: The number of related articles on the page should not be too many, usually 5-10 articles is a suitable range, and it can be done throughlimitParameters are controlled. Too many recommendations may distract the user's attention.
  • Diverse sortingIn addition to the default sorting, try usingorderParameters, such as sorting byviews desc(View count descending) Recommend popular articles, or bycreated_time desc(Publish time descending) Recommend the latest articles, increasing the diversity of recommendations.
  • Cache mechanism:For frequently accessed article pages, consider caching related article list data on the front end or server side to reduce API requests during each page load and improve website performance.

By skillfully applyingtype=relatedPattern, AnqiCMS-driven websites can bring stronger internal link structures and better user browsing experiences, allowing your content to be discovered and utilized more effectively.


Common Questions (FAQ)

Q1: Why did I settype=relatedbut the interface returneddatathe array is empty?A1: There are usually several reasons for returning an empty array. First, please check if you have correctly passed the current article'sidParameter, this istype=relatedThe unique benchmark for relevance matching in the mode. IfidInvalid or missing, the interface will not work.其次,AnqiCMS会尝试根据文章的分类、关键词等信息进行匹配,如果当前文章缺乏这些关联信息,或者数据库中确实没有足够的相关文章可以推荐,也可能导致返回空列表。You can try to add more relevant tags and keywords to the article and make sure there is enough other content associated with it.

Q2:type=relatedHow do I judge the relevance of the article? Can I customize the relevance matching algorithm?A2: AnqiCMS internally usually matches based on the common classification, tags, keywords, etc. of the 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 for directly customizing the relevance matching algorithm.But, you can indirectly influence and optimize the recommendation effect of related articles by carefully planning the classification system of the articles, accurately setting the tags and keywords of the articles, and adding more contextual information to the content of the articles themselves.

Q3: How can I get related articles under a specific category only?A3: If you want to limit the scope of related articles to a specific category, in addition to settingtype=relatedof the current article'sidyou should also providecategoryIdParameter, and set its value to the category ID of the current article. For example: `id=123&type=related&categoryId=