Understanding which content is more popular and which topics are more likely to spark discussion is crucial for optimizing content strategy when operating a website.AnQiCMS (AnQiCMS) provides us with a convenient way to obtain these key data, such as the number of page views and comments on articles.Here we will look at how to get this information through the AnQi CMS API interface in detail.

Get the view count and comment count of a single document

When you need to view the popularity of a specific article, the "Get Document Details Interface" of Anqi CMS is your preferred tool.This interface can provide you with comprehensive information about a document, including the browsing volume and comments we are concerned about.

To use this interface, you need to send a request to the address under your website domain./api/archive/detailAddress.GETOf course, remember to replace it with your actual website address.{域名地址}Replace it with your actual website address.

When sending a request, you need to tell the interface which document you want to query. This can be done in two ways:

  • Pass the document'sid, which is an integer.
  • Or if you know the document's URL alias (filename), you can also pass this string. Either one will do.

For example, suppose you have a document with an ID of1You can construct your request like this:https://你的域名/api/archive/detail?id=1

After you send this request, AnQi CMS will return a JSON packet. In this packet'sdataPart, you will find many details about this document. Among them, there are two fields that we have been looking for:

  • viewsThis value is an integer that accurately tells you how many times this document has been viewed so far.
  • comment_countThe same integer, it shows the total number of comments received on this document.

By these two fields, you can clearly see how many people have viewed this document and how much discussion it has sparked. This is very helpful for assessing the influence of a single article.

Batch retrieval of document views and comment counts

This interface is located{域名地址}/api/archive/list, also acceptsGETrequests. It allows you to filter out the document list you want by various conditions.

To get a list of documents containing views and comments, you must specify at leasttype="page". This way, the returned data will not only contain the document list, but also include atotalField displays the total count, making it easy for you to paginate. You can also combine other parameters to precisely locate:

  • moduleId: If you want to get documents under a specific model (such as an article model or a product model).
  • categoryId: If you only want to see documents under a specific category.
  • orderThis is a very useful parameter, for example, you can setorder="views desc"to sort by views from high to low, ororder="comment_count desc"to sort by the number of comments.
  • limitandpage: Controls how many items are displayed per page and which page of data is retrieved, convenient for pagination display.

The interface returnsdataPart will be an array, where each element represents a brief information of a document. Similarly, each document object also containsviewsandcomment_countthese fields.

Through this interface, you can easily build various rankings, such as "Top Articles of the Week

Tips in practical application

The key is to understand the request methods and return structures of these API interfaces when obtaining the views and comments of a single or multiple documents.Integrate this data into your website frontend display, which can make content operation more data-supported.For example, you can add view count and comment icons to each article on the article list page, or prominently display these data on the article detail page to encourage user interaction.

Remember, all API requests in{域名地址}must be replaced with your actual website domain, which is the basis for accessing the Anqi CMS API.


Frequently Asked Questions (FAQ)

Ask: What I gotviewsorcomment_countWhy is it always 0?Answer: This may be because the document has not been viewed or commented on, or the comments are currently under review.The view count of AnQi CMS usually increases automatically when the page is visited.If a document is newly released, it may take some time to generate traffic.comment_count. You can also check the requestedidorfilenamewhether it is correct, make sure you are querying the correct document.

How to sort the display list of articles based on views or comment numbers?Answer: When using the "Get Document List Interface" (/api/archive/list) you can sort throughorderParameters to specify the sorting method. For example, to sort by views from highest to lowest, you can setorder="views desc"; To sort by comments from highest to lowest, you can setorder="comment_count desc"If you want to sort by creation time, you can useorder="created_time desc".

Can I directly call these API interfaces on the front-end page?Answer: In principle, it is permissible, but for safety and performance considerations, it is more recommended to call these APIs on the server side.If you must call directly from the front end, make sure your API request follows the CORS (Cross-Origin Resource Sharing) strategy and does not leak any sensitive information.For APIs that require Token authentication, be sure to keep your authentication information secure and avoid exposing it directly in frontend code.