How to get the current view count (`views`) and comment count (`comment_count`) of the document?

Calendar 👁️ 75

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

If your requirement is to obtain the views and comments of multiple documents on a website, even all documents in a certain category, and then sort or display a 'popular articles' list based on this data, then querying individually would clearly be inefficient.At this moment, the 'get document list interface' comes into play.

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.

Related articles

What do the `module_id` and `category_id` fields represent in the document details, and can you further query model or category details through them?

## Unveiling the details of Anqi CMS document `module_id` and `category_id`: What do they mean?When using AnQi CMS for content management and website operation, we often obtain various data through API interfaces, among which the document detail interface (`/api/archive/detail`) is the key to obtaining the core information of a single article.In the returned data of this interface, you may notice the `module_id` and `category_id` fields.

2025-11-09

What role does the `url_token` field play in the document details, and how is it associated with the `filename` parameter?

In the daily use of Anqi CMS, we often encounter the `url_token` field, especially when dealing with document details and URL structures.It is closely related to the `filename` parameter in the API interface. Understanding the relationship between the two is crucial for better management of website content, optimizing user experience, and improving search engine performance.### `url_token`:The "friendly" identity tag of content `url_token` is simply the term used in the AnQi CMS system for various types of content (such as documents

2025-11-09

How to get the SEO title (`seo_title`), keywords (`keywords`), and description (`description`) of a document?

In website operation, setting clear and targeted SEO titles (`seo_title`), keywords (`keywords`), and descriptions (`description`) is a key step in improving search engine rankings.AnQiCMS (AnQiCMS) provides a convenient way to manage and obtain these important SEO metadata.Whether you need to dynamically set this information for a single page or process a large amount of content in bulk, it can be easily achieved through the provided API interface.

2025-11-09

What are the common meanings of the `code` and `msg` fields in the document details interface?

When using AnQiCMS for website development or integration, we often deal with API interfaces.When handling the return results of these interfaces, the `code` and `msg` fields are almost indispensable parts of all response data.They play the role of 'traffic lights' and 'instruction manuals', helping us quickly understand the processing results of the request, whether successful or not.### `code` field: Quickly judge the status code of the request result The `code` field is an integer value

2025-11-09

How is the `images` field (document group image) stored and parsed in the document details?

When using AnQiCMS to manage website content, images are undoubtedly an important element in enhancing the attractiveness of the content, especially when we want to add a series of related images to the document, the album feature becomes particularly crucial.So, how are these group images stored and parsed in the AnQiCMS document details?Understanding this will help us better utilize AnQiCMS for content creation and display.### The storage mechanism of document group charts First

2025-11-09

What do the `logo` and `thumb` fields represent in the document details, and what is the difference between them?

When managing content in Anqi CMS, we often encounter questions about image fields, especially the `logo` and `thumb` fields, which are both involved in image representation in the document detail interface (`archiveDetail`), but have subtle yet important differences in actual use and meaning.Understanding their differences can help us better optimize the visual presentation and loading performance of the website.### `logo` field: the "identity card" of the document When we talk about the `logo` field

2025-11-09

How to interpret the `flag` recommended attribute in the document details, for example, what do `h`, `c`, `f`, and others represent?

In AnQi CMS, the recommended attribute `flag` is a very practical feature in content operations. It allows us to classify and label document content, thereby enabling personalized display and filtering in different areas of the website.Understanding the meaning of these brief letter codes can help us manage and present website content more efficiently.Where can I find the `Flag` attribute? This important `flag` attribute appears in several key interfaces, it is both the characteristic of the document itself, and the important basis for querying and filtering documents. First

2025-11-09

What is the role of `canonical_url` and `fixed_link` in document details for SEO and link management?

In website operation, the health status of links and the friendliness to search engines are the foundation for the success of the website.AnQi CMS provides us with two key fields: `canonical_url` and `fixed_link`, which play a crucial role in document details and help us optimize the search engine performance of the website and effectively manage links. ### canonical_url: Define the "main version" of the content Imagine that your website might have multiple URLs pointing to the same or highly similar content for various reasons.

2025-11-09