How to get the documents of a specified user, or only display the documents under the current category without including subcategories?
As an experienced website operations expert, I am well aware of the importance of a flexible and efficient content management system for website operations.AnQiCMS, with its lightweight, high-performance, and highly customizable features, has won the favor of many small and medium-sized enterprises and content operators.In the daily content operation, we often need to manage and display the website content in a refined manner, among which, how to accurately obtain the documents of a specific author, or only display the content under the current category while excluding the subcategories, is the key to improving user experience and optimizing the content structure.Today, let's delve deeperarchiveListThese two powerful functions of the tag.
Security CMSarchiveListDeep analysis: Accurately obtain documents and flexible classification control.
In AnQi CMS,archiveListThe tag is undoubtedly the core of content display. It acts as a powerful filter, helping us extract documents that meet specific conditions from a vast amount of content (including articles, products, etc.), and present them in various forms on the website front end.Whether it is to display the latest news, hot products, or build complex special pages,archiveListThey all play an indispensable role. It follows the concise syntax of the Django template engine, through{% tag %}to define tags,{{ variable }}to output variables, making template development intuitive and efficient.
By default, we may simply callarchiveListto get the latest document list under a certain model:
{% archiveList archives with moduleId="1" type="list" limit="5" %}
{% for item in archives %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% empty %}
<li>暂无文档。</li>
{% endfor %}
{% endarchiveList %}
However, the strength of AnQi CMS is far from over. When we need to control the content source more finely,userIdandchildthese two parameters can play their unique role.
I.驾驭内容发布者:userIdThe magic of parameters
In a multi-user or multi-author collaboration website environment, such as a blog written by multiple experts or a platform showcasing works of different creators, we may need to list all the documents published by a specific author individually. At this point,archiveListofuserIdThe parameters come into play.
userIdParameters allow us to specify a user ID,archiveListIt will only return all the documents published under the user ID. This is extremely useful for building personal author columns, showcasing edited featured content, or for the convenience of users to view their own published content.The user ID is usually a unique identifier assigned by the Anqicms backend to each administrator or content publisher.
Imagine, in a blog named "Science Exploration", the user ID is:1The author is "Dr. Zhang", the user ID is:2The author is "Li Engineer". If we want to display all the articles of "Zhang Doctor" on a specific page, we just need to use it like this.userIdparameters:
{% archiveList archives with userId="1" moduleId="1" type="list" limit="5" %}
{% for item in archives %}
<li>【作者 ID: {{ item.UserId }}】<a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% empty %}
<li>该作者暂无文档发布。</li>
{% endfor %}
{% endarchiveList %}
In this way, we can easily create a personal homepage for each author, dynamically displaying their portfolio, greatly enhancing the organization and personalization of the content.This also helps to establish the personal brand of the author and enhance the sense of belonging and stickiness of users.
II. Precision Focusing on Classification: childThe magic of the parameter
The AnQi CMS content classification system usually supports a hierarchical structure, for example, under 'News Center' there may be subcategories such as 'Company News' and 'Industry Dynamics'. In many cases, we need to display all the content of the parent category page, including the documents of the subcategories, which is alsoarchiveListThe default behavior of the label (childThe parameter is set to default.true)。However, sometimes our operational goal is to let users focus only on the content of the current parent category itself, while ignoring the documents of its subcategories, in order to achieve a more accurate topic focus.
At this time,childParameters are particularly crucial. When wechildthe parameter tofalsethen,archiveListWill only retrieve the specifiedcategoryIdDocument under, without including any sub-category documents.
For example, if the "News Center"'categoryIdIs10The company news is10The subcategory, if we want to display only the documents directly published to the 'News Center' category on the 'News Center' page and not show any 'Company News' or other subcategory documents, we can configure it this wayarchiveList:
”`twig {% archiveList archives with categoryId=“10”