How to get the link and title of the 'previous' or 'next' document by using the `id` of the current document through other interfaces?

Calendar 👁️ 80

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.

Related articles

Does the data structure returned by the document detail interface change for different types of documents (such as articles and products)?

When building a website with AnQiCMS, we often need to obtain detailed information of various documents through the API interface.The `archive/detail` interface is the key to obtaining the details of a single document.Many developers and content operators may be curious, whether the data structure returned by this interface is different for different types of documents, such as ordinary articles, news, or product information on e-commerce websites.The answer is: it has both unity and high flexibility.First, Anqi CMS is in design

2025-11-09

How to ensure the uniqueness of document URL alias queries to avoid ambiguity?

When using AnQi CMS for content management, URL aliases (also known as URL Tokens) are a key component for building user-friendly and SEO-optimized websites.It not only makes your page address more readable, but also helps search engines better understand the content topic.However, it is particularly important to ensure the uniqueness of the document when querying through these URL aliases, otherwise it may cause the system to identify confusion, users to access incorrect pages, and even affect the SEO performance of the website.

2025-11-09

Does the document detail interface directly provide the detailed content of the document's category (`category.content`)?

When using AnQi CMS for website development or content integration, it is often necessary to obtain documents and their related information.One of the common questions is: When getting the details of a document, can we also get the detailed content of the category to which the document belongs, especially fields like `category.content`?According to the documents provided by AnQi CMS, we can clearly find the answer.To be direct, **yes, the AnQi CMS document detail interface (`/api/archive/detail`) indeed provides detailed content of the document's category

2025-11-09

What does it mean if an error code 1001 or 1002 occurs when getting the document details, and how to solve it?

When using AnQi CMS for website content management and development, we often use API interfaces to obtain various data, among which obtaining document details (`/api/archive/detail`) is very commonly used.When you call this interface, if you encounter system return codes 1001 or 1002, it usually indicates that the request was not successfully processed and a specific reason is given.Understanding the meaning and solutions of these error codes can help us more efficiently troubleshoot problems and ensure the normal display of website content.### Error Code 1001

2025-11-09

How to use AnQi CMS API to check if a specific document has been paid before viewing?

When building and operating modern websites, especially when your platform involves high-quality content or exclusive resources, how to effectively manage content access permissions is a core issue.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface that allows you to precisely control document viewing conditions, including determining whether a specific document requires payment and whether the user has completed the payment.We will discuss how to use the API provided by AnQiCMS to check if a specific document has been paid for before it can be viewed, ensuring that your paid content is properly protected.###

2025-11-09

How can I verify the password submitted through the API to obtain the document content if the document is protected by a password?

In Anqi CMS, content management not only covers the regular article publishing and display, but also provides flexible mechanisms to protect sensitive or exclusive content.When you need to allow users to access specific document content by entering a password, Anqicms provides a clear API interface to implement this function.This is very useful for building paid content, VIP areas, or internal material sharing scenarios.### Core Function: Document Password Verification API

2025-11-09

Does the `user_id` field in the document details indicate the document publisher or author ID?

When managing website content in AnQi CMS, we often encounter various data fields, among which the `user_id` field is a common and easily questionable identifier.When we retrieve document details from Anqi CMS, what does this `user_id` represent, the publisher or the author?To clearly understand this point, we need to analyze the data structure returned by the document interface.Firstly, from the `archiveDetail.md` document to get the API return parameters of the document details view

2025-11-09

How to use the `msg` field for precise error checking when the document detail interface returns `code: -1`?

Guide to troubleshooting when the AnQiCMS document detail interface returns `code: -1` When using AnQiCMS for website content management, we often use the provided API interface to retrieve or manipulate data.When calling the document detail interface (for example, `/api/archive/detail`), if the returned result contains a `code` field of `-1`, this usually means that the request was not successful, and an error occurred during the server-side processing.In such a situation, many users may feel confused

2025-11-09