In AnQi CMS, tags (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 browsing the details page of a document, it is often hoped to see a list of all tags associated with the document. This not only helps users discover more relevant content but also enriches the semantic structure of the page.
To retrieve the list of tags 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.
第一步:Get the unique identifier (ID) of the document
In the AnQi CMS, each document has a unique ID. This is the key to obtaining tags later. You canarchive/detailThe interface is used to get detailed information of a single document, which includes this ID.
The calling method of this interface isGET. You can specify the document to be queried in two ways:
- Using the document ID:If you already know the document's digital ID, you can use it directly as
idParameter passing. - Use the document URL alias:If you know the document's URL alias (
filename) you can also use it to query.
For example, if you know the ID of a document is 1, you can send{域名地址}/api/archive/detail?id=1a GET request.
After the interface returns successfully, you will find a field nameddatain the returned data.idThe integer value, which is the unique ID of this document. You will also see the document'skeywordsThe field, which is typically a collection of keywords in the document, but 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 retrieve the associated tags. The AnQi CMS provides a dedicatedtag/listInterface, it can list all related tags according to the document ID.
You also need to useGETmethod 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{域名地址}/api/tag/list?itemId=1a GET request.
The interface will return an array containing a label objectdataEach object in the array represents a label and usually contains the following important information:
id: The unique ID of the label.title: The name of the label, which is also the label text we usually see.url_token: The URL alias of the label, which can be used to build a dedicated link for the label.link: The details page of the label, click to view all documents containing this label.
Through iteration of thisdataAn array, you can retrieve all tags associated with the current document, and you can display them in any location 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:
- Pass
GET {域名地址}/api/archive/detail?id={文档ID}(or use)filename)To obtain the detailed information of the current document, extract theid. - Then, use this
idasitemIdparameter, to callGET {域名地址}/api/tag/list?itemId={文档ID}You can 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 access methods. When displaying on the front end, you can usetitleAs label text,linkas a hyperlink for labels, thus building an interactive label cloud or related content navigation area, greatly enhancing the user's browsing experience.
Common Questions (FAQ)
Q1: If the document has not been set with any tags,tag/list接口会返回什么?
A: If the document is not associated with any tags,tag/listthe interface'sdataThe field will return an empty array. This means that when you are handling the interface response, you need to checkdataThe array is empty, if it is empty, you can choose not to display the label area, or display a prompt such as 'No labels available'.
Q2:archive/detailReturned by the interface.keywordsfield andtag/listThe data obtained from the interfacetagsWhat is the difference?
A:archive/detailin the interfacekeywordsThe field is usually a key word in the document, they are plain text, such as “安企CMS,CMS system,website tutorial”, mainly used for SEO purposes, to inform the search engine of the document's topic. And throughtag/listThe data obtained from the interfacetagsIs an array of structured label objects, each with its own ID, title, and independent link.In the AnQi CMS, these tags are treated as independent content entities, more suitable for building clickable tag clouds or related content navigation, with stronger interactivity and content aggregation capabilities.
Q3: Can we get a document's tags without first obtaining the document details?
A: Cannot directly retrieve the label list of a specific document without knowing the document ID.tag/listthe interface'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.archive/listInterface search document, then extract the ID from the search results) to get the document ID, but in the end, you still need the document ID to calltag/listinterface.