How to get the articles published by a specified user (`user_id`) through the AnQiCMS document list?

Calendar 👁️ 99

In website content operations, we often need to display all articles by a specific author, such as on the author's personal homepage, or aggregate the content of specific contributors on a special topic page.AnQiCMS (AnQiCMS) provides a powerful and flexible API interface, allowing us to easily meet this requirement.

To get the articles of a specified user (user_idThe list of all articles published, we need to usearchive/listThe interface is the core function of AnQi CMS used to retrieve document lists, which allows us to filter and sort through various conditions, including filtering by the author of the article.

Core function analysis:archive/listInterface

archive/listThe calling address of the interface is usually{域名地址}/api/archive/list, its calling method isGETRequest. The key to understanding this interface is its request parameters, especially those that help us accurately locate the filtering conditions of the articles.

The API returns data where each article object contains auser_idField, this is the unique identifier of the article publisher. Its request parameters are designed very flexibly, although they are not listed directly in the documentuser_idAs an independent filter parameter, but in the description of 'Custom filter parameters', it is explicitly stated that we can filter any field existing in the document through the URL query parameters. Therefore, we can directlyuser_idPass as a request parameter toarchive/listinterface.

exceptuser_idSome other parameters are also very useful when building the request:

  • type: Recommended to be set aspage. WhentypeWithpageThe interface will return the total number of articles whentotalThis is crucial for building pagination functionality.
  • limit: It is used to control the number of articles displayed per page. You can set it as needed, for example.limit=10means 10 articles per page.
  • page: WhentypeWithpageIt takes effect at this time, used to specify which page of content to retrieve.
  • order: Used to specify the sorting method of the article, for examplecreated_time descIt can bring the latest published articles to the forefront.

Practical Operation: Build Your API Request

Suppose we want to retrieveuser_idWith123The user has published all articles and wants to display 10 per page, sorted by publication time in descending order, and also get the content of the first page. So, we can build the API request like this:

GET {域名地址}/api/archive/list?user_id=123&type=page&limit=10&page=1&order=created_time desc

Please remember to replace{域名地址}with the actual domain name of your website.

The meaning of this request is:

  • Byuser_id=123Precisely filter out the articles published by user ID 123.
  • type=pageTell the system that we need to perform pagination queries and return the total number.
  • limit=10Specify that 10 articles should be returned per page.
  • page=1Indicates that we are currently requesting the articles for the first page.
  • order=created_time descMake sure the articles are arranged in chronological order from new to old.

Understand the returned data

After you send the above request, you will receive a JSON formatted response. A successful response iscodeThe field is usually0. The core content existsdatain the field, it is an array containing article objects.

{
  "code": 0,
  "data": [
    {
      "id": 101,
      "title": "用户123发布的第一篇文章",
      // ... 其他文章信息 ...
      "user_id": 123,
      "created_time": 1700000000
    },
    {
      "id": 102,
      "title": "用户123发布的第二篇文章",
      // ... 其他文章信息 ...
      "user_id": 123,
      "created_time": 1699900000
    }
    // ... 更多文章 ...
  ],
  "total": 50, // 假设用户123共有50篇文章
  "msg": ""
}

EachdataEach element in the array represents a document, which explicitly containsuser_idThe field verifies the accuracy of our filtering. At the same time,totalThe field will tell you the total number of articles that meet the criteria, which is very practical for displaying the total page number and navigation on the front-end page.

Application scenarios in practice

In this way, you can create a dedicated article list page for the contributors or authors of the website. When a user visits a specific author's personal homepage, you can dynamically call this API and pass in the author'suser_idDisplay all the articles contributed. CombinedlimitandpageParameter, can easily achieve pagination of the article list, improving user experience.

Furthermore, you can also apply this method to more complex scenarios, such as:

  • In the "My Posts" feature, allow users to view all the articles they have published.
  • Build a content aggregation page, displaying the most popular articles published by a specific user group.

Of Security CMSarchive/listThe interface provides us with great convenience and flexibility, making content management and display efficient and simple.


Frequently Asked Questions (FAQ)

1. How can I retrieve their information if I only know the user's nickname or username?user_id?If you only know the user's nickname or username, and do not have direct access to their information,user_idYou may need to call other user-related APIs, such asapi/user/detailinterfaces, if the interface supports querying by username), or through any known article published by the userarchive/detailInterface, find it in the returned datauser_idField. Once obtaineduser_id, it can be applied toarchive/listInterface for filtering

2. Besidesuser_id, can I also use other conditions to filter the articles at the same time?Of course you can.archive/listThe interface supports combining multiple filtering conditions. For example, you can specifyuser_id/categoryId(Article Category ID),q(Search Keywords) andflag(Recommended attributes) and other parameters to achieve more refined article list filtering. Simply pass these parameters through&the symbol to connect in the URL.

3. How to handle the situation where no articles have been published?user_id?If the input includesuser_idthe corresponding user has not published any articles, or theuser_iddoes not exist,archive/listdata returned by the interface containsdatathe field will be an empty array[]at the same timetotalthe field will display0. Your front-end application can use this information to display friendly prompts to users such as 'This user has not published any articles'.

Related articles

What is the significance of the `price` and `stock` fields returned by the `archive/list` interface for e-commerce document models?

In AnQi CMS, when you retrieve the document list through the `archive/list` interface, the returned data includes the `price` and `stock` fields, which are of vital importance for constructing an e-commerce website model.They are not just simple numbers, but are the core elements supporting product display, transaction process, and inventory management.

2025-11-09

I want to display the number of comments for each article on the AnQiCMS document list page, which field should I check?

In the daily use of AnQiCMS, many operators hope to be able to directly display the number of comments for each article on the article list page.This not only effectively enhances the activity of the content, but also helps users quickly understand which articles are more popular and have more discussion value.Then, among all the data fields, which one should we focus on in order to meet this requirement?

2025-11-09

How to ensure that only documents under the parent category are returned when retrieving the AnQiCMS document list, without including subcategories?

When using AnQi CMS to manage website content, we often encounter situations where we need to precisely control the display range of documents.For example, when you want to display only the documents directly published under a certain parent category page, without involving the content of its subordinate subcategories, you need to adjust the way the document list is retrieved.AnQi CMS provides a very flexible API interface, allowing you to easily meet this requirement.

2025-11-09

What is the role of `url_token` in the AnQiCMS document list results, and how is it used to generate friendly URLs?

In AnQiCMS, `url_token` is a crucial concept, it is not only a field in the document list, but also the core element for building friendly URLs (Friendly URL) of the website.Understanding its role and usage can help us better optimize the website structure, improve user experience, and search engine rankings.

2025-11-09

What is the default behavior and return content of the `archive/list` interface when no parameters are passed?

## In-depth Analysis of AnQiCMS `archive/list` Interface: Default Behavior and Return Content when No Parameters Are Provided When developing or managing websites with AnQiCMS, we often need to obtain various data through API interfaces.The `archive/list` interface is one of the core interfaces for obtaining the document list of the website.Understanding its default behavior and return content when no parameters are passed is crucial for efficient data acquisition and initial debugging.

2025-11-09

How to implement a 'Hot Articles' or 'Most Viewed' list, achieved through the `order` parameter?

In website operation, we all hope to display the most popular and highly read articles to visitors, such as common lists like "Hot Articles" or "Most Viewed".This not only effectively guides users to discover more exciting content and improve the user experience of the website, but it is also an indispensable part of content operation.In AnQi CMS, implementing such a feature is simpler than you imagine, the secret is hidden in the `archive/list` interface's `order` parameter.

2025-11-09

What will `data` and `total` return if no documents meeting the criteria are found in the AnQiCMS document list?

When building a website or application with AnQiCMS, we often need to use its provided API interface to retrieve various content, such as document lists.What data structure will the API return when our query conditions do not match any content?Especially the `data` and `total` fields, which are crucial for our proper data handling.Today, let's delve into how AnQi CMS responds when it does not find a document that meets the criteria in the document list.

2025-11-09

What is the help of `archive/list` interface returned `canonical_url` and `fixed_link` fields to SEO optimization?

In the ocean of website content, how can our high-quality content stand out and be discovered by more potential users, which is a topic that every content operator continuously explores.Search engine optimization (SEO) is one of the key strategies to achieve this goal.In SEO practice, the URL plays an extremely important role.

2025-11-09