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

skillfully utilize the API to build article navigation

AnQi CMS provides a very intuitive interface for retrieving the previous and next articles: /api/archive/prevand/api/archive/nextThese two interfaces are designed to meet the navigation needs of the article detail page, they only need the current article'sidas a parameter, it can return the links and titles of adjacent articles.

To get the current article'sPreviouswe can call/api/archive/previnterface. You just need to pass the article you are currently reading'sidand Anqicms will return theidDetails of the corresponding previous article. The returned data includesid/title(Article Title) andlink(article link) and other keyword fields. ThroughlinkFields, we can directly build 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, we use/api/archive/nextInterface. Its calling method is 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 operations

In practical development, when your website template needs to display the 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 obtain the unique identifier of the current article from the page URL or through/api/archive/detailthe response of the interfaceid.
  2. Initiate an API request:
    • To{域名地址}/api/archive/prevSend aGETRequest and include the current article's parameters in the requestid.
    • At the same time, towards{域名地址}/api/archive/nextSend aGETRequest, including the current article's parameters as wellid.
  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 point, you can fromdataobjecttitleField as navigation button text and extractlinkField as navigation button jump address.
    • IfdataField isnullIt means that the current article is already 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.


Frequently Asked Questions (FAQ)

1. If the current article is the first or last in the category,archive/prevorarchive/nextWhat will the interface return?

When you request the previous article, and the current article is already the first in the sequence,/api/archive/previnterface'sdataThe field will returnnullSimilarly, when requesting the next article, and the current article is the last one,/api/archive/nextinterface'sdatathe field will also returnnullThis allows you to easily judge and handle the display status of the navigation buttons.

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

These two interfaces usually base on the article'sid(defaulting to ascending) or publication timecreated_timeFind adjacent articles in the same category or the entire document library.The two interfaces of Anqi CMS are designed to intelligently search for previous and next documents within the context of the current document (such as the same category, same module) to ensure the logic of navigation.If you need more fine-grained control (for example, sorting by creation time only under specific conditions), you may need to combine/api/archive/listinterface for customized queries.

3. Besides the title and link, I can also extract fromarchive/prevorarchive/nextAre you getting other article information from the interface response?

Yes.archive/prevandarchive/nextinterface indataThe field actually returns a complete document object with/api/archive/detailThe interface returnsdatathe same structure. This means you can not only get toid/titleandlink, can get such asthumb(thumbnail),description(Summary),views(Views) and all available article field information. This provides greater flexibility in designing page navigation, such as displaying thumbnails or brief descriptions next to navigation buttons.