In content-based websites, users often hope to easily navigate from the current article to the previous or next article. This continuous reading experience is crucial for enhancing user satisfaction and the website's PV (page views).The autoCMS (AnQiCMS) provides a simple and efficient API interface to implement this feature, allowing developers to easily integrate 'Previous/Next' navigation on the article detail page.

Deliciously utilize API to build article navigation

AnQi CMS provides a very intuitive interface for fetching the previous and next articles:/api/archive/prevand/api/archive/next。These two interfaces are designed to address the navigation needs of the article detail page, and they only need the current article as a parameter to return the links and titles of adjacent articles.idAs a parameter, they can return the links and titles of adjacent articles.

To get the current article'sPrevious articlewe can call/api/archive/previnterface. You just need to pass theidto, and the Anqi CMS will return theidThe detailed information of the corresponding previous article. The returned data includesid/title(article title) andlink(article link) and other keyword fields. BylinkField, we can directly construct a hyperlink to jump to the previous article, andtitlewhich can be used as the text content of the navigation button.

Similarly, to get the current article'sNext articlewe use/api/archive/nextInterface. Its calling method is exactly the same as getting the previous one, and it only needs to provide the current article'sid. The interface will return the next article'sid/titleandlink.

logical considerations in actual operation

In practical development, when your website template needs to display navigation for previous and next articles, you can follow the following steps:

  1. Get the current article ID:When a user visits the detail page of any article, we first need to get the unique identifier of the current article from the page URL or through/api/archive/detailthe response of the interfaceid.
  2. to start the API request:
    • to{域名地址}/api/archive/prevaGETRequest, and include the current article in the request parametersid.
    • At the same time, towards{域名地址}/api/archive/nextaGETRequest, and also include the current articleid.
  3. Process the API response:
    • For these two requests, we need to check the returneddatafield.
    • Ifdatafield is notnull, which means there is a previous or next article. At this time, you can fromdatathe object.titleField as the text of the navigation button, and extractlinkField as the navigation button jump address.
    • Ifdatathe field isnullIt indicates that the current article is the first article in the sequence (for the previous navigation) or the last article (for the next navigation).In this case, you can choose to hide the corresponding navigation button or gray it out to inform the user that there is no more content.

Through such a mechanism, your website can provide users with a smooth, seamless article switching experience, greatly enhancing the discoverability of content and the duration of user reading.


Common Questions (FAQ)

1. If the current article is the first or last in the category,archive/prevorarchive/next接口会返回什么?

When you request the previous article, and the current article is already the first in the sequence,/api/archive/prevthe interface'sdatathe field will returnnull. Similarly, when requesting the next article, and the current article is the last one,/api/archive/nextthe interface'sdatathe field will also return,null. This allows you to easily judge and accordingly handle the display status of the navigation buttons.

2.archive/prevandarchive/nextWhat is the order of the articles returned by the interface? Do they consider the category of the articles?

These two interfaces usually sort the articles byid(default is ascending) or publish timecreated_timeFind adjacent articles within the same category or the entire document library.These two interfaces of Anqi CMS are designed to intelligently search for preceding and succeeding documents within the context of the current document (such as: the same category, the same module) to ensure the logic of navigation./api/archive/listInterface for custom query.

3. Besides the title and link, can I also get other article information fromarchive/prevorarchive/nextthe interface response?

Yes, it can.archive/prevandarchive/nextthe interface?dataThe field returns an actual complete document object, which is the same as/api/archive/detailReturned by the interface.dataThe structure is the same. This means you can not only getid/titleandlink, but also get such asthumb[Thumbnail],description[Summary],views(Views)and all available article field information.This provides greater flexibility for designing page navigation, for example, you can display thumbnails or brief descriptions next to the navigation buttons.