In Anqi CMS, tags are an important tool for organizing content, enhancing user experience, and optimizing search engine rankings.They can help visitors quickly find relevant content, and also allow website administrators to better manage information.When we browse a document detail page, we often hope to see a list of all tags associated with the document, which can not only guide users to discover more related content but also enrich the semantic structure of the page.

To obtain the tag list associated with a specific document, we usually need to perform two steps: first, determine the unique identifier of the target document, and then use this identifier to request the associated tag data.

Step 1: Obtain the unique identifier (ID) of the document

In Anqi CMS, each document has a unique ID. This is the key for obtaining tags later. You can access it byarchive/detailAn interface to retrieve detailed information about a single document, which includes this ID.

The calling method of this interface isGET. You can specify the document to query in two ways:

  1. Using the document ID:If you already know the document's numeric ID, you can pass it directly asida parameter.
  2. Use the document URL alias:If you know the document's URL alias (filename),can also be used to query.

For example, if you know the ID of a document is 1, you can send a GET request to{域名地址}/api/archive/detail?id=1send a GET request.

After the interface successfully returns, you will see the data returned in thedataFind a field namedidinteger value, this is the unique ID of the document. You will also see the document'skeywordsThe field, which is usually a collection of keywords in the document, but it is not the structured tag list we are looking for.

Step two: Use the document ID to obtain the associated tag list.

With the unique ID of the document, it becomes very direct to obtain the associated tags. Anqi CMS provides a specialtag/listAn interface that can list all related tags based on the document ID.

You also need to useGETa method to call this interface. The most critical parameter isitemIdYou need to assign the document ID obtained in the first step to this parameter.

For example, if the document ID obtained in the first step is 1, then you can send to{域名地址}/api/tag/list?itemId=1send a GET request.

The interface returns an array containing tag objectsdataEach object in the array represents a tag, which usually includes the following important information:

  • id: The unique ID of the tag.
  • title: The name of the tag, which is the text we usually see.
  • url_token: The URL alias of the tag, which can be used to build the exclusive link of the tag.
  • link: The detail page link of the tag, click to view all documents containing the tag.

By traversing thisdataAn array, you can get all the tags associated with the current document, and you can display them in any position on the page as needed, such as below the article content, or in the sidebar.

Summarize the workflow

The entire process of obtaining document-related tags can be summarized as:

  1. ByGET {域名地址}/api/archive/detail?id={文档ID}(or use)filename)Get the detailed information of the current document, and extract the document'sid.
  2. Then, use thisidasitemIdThe parameter, callGET {域名地址}/api/tag/list?itemId={文档ID}To get the detailed list of all tags associated with the document.

This two-step operation not only clearly separates document information and tag information, but also provides developers with flexible data acquisition methods. When displayed on the front end, you can utilizetitleAs label text,linkAs a hyperlink for the label, thus constructing an interactive label cloud or a related content navigation area, greatly enhancing the user's browsing experience.


Frequently Asked Questions (FAQ)

Q1: If the document has not set any tags,tag/listWhat will the interface return?

A: If the document is not associated with any tags,tag/listinterface'sdataThe field will return an empty array. This means that when you are handling the API response, you need to checkdataWhether the array is empty, if it is empty, you can choose not to display the label area, or display prompts such as 'No labels available'.

Q2:archive/detailThe interface returnskeywordsandtag/listThe data obtained from the interfacetagsWhat is the difference?

A:archive/detailthe interface inkeywordsFields are typically keywords in a document, they are plain text, such as 'AnQi CMS, CMS system, website tutorial', mainly used for SEO purposes, to inform search engines of the document's topic. And throughtag/listThe data obtained from the interfacetagsis a structured array of tag objects, each tag has its own ID, title, and independent link.In AnQi CMS, these tags are considered independent content entities, more suitable for building clickable tag clouds or related content navigation, with stronger interactivity and content aggregation capabilities.

Q3: Can you directly get the label of a document without first obtaining its details?

A: You cannot directly retrieve the tag list of a specific document without knowing the document ID.tag/listinterface'sitemIdThe parameter is required, it explicitly indicates which document's label to query.Therefore, obtaining the document ID is a prerequisite step for obtaining its associated tags.Of course, you can use other methods (such as througharchive/listSearch for the interface document, then extract the ID from the search results to obtain the document ID, but in the end, we all need the document ID to calltag/listinterface.