As an experienced website operations expert, I know that the core value of the Content Management System (CMS) lies in its flexibility and fine control over content display.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture based on the Go language and a rich set of features.In terms of daily content operations, how to efficiently organize and display the document list under the tag (Tag), while providing friendly pagination and sorting functions, is a key factor in improving user experience and website SEO performance.
Today, let's delve into how to skillfully combine built-in template tags in AnQiCMS to achieve pagination and flexible sorting of the tag document list.
The label and content organization in AnQiCMS
In AnQiCMS, tags are an indispensable part of content organization.It allows us to associate documents with common themes or keywords, even if these documents belong to different categories or models.By using the "Content Management" module under the "Document Tags" feature, we can easily create, edit, and manage all tags on the website.Each tag can have its own name, description, and custom URL, which provides great convenience for SEO optimization.
When a user visits a specific tab, they usually expect to see all the relevant documents under that tab. These document lists are generally created through special template files (usuallytag/list.htmlRender and use the powerful template tags built into AnQiCMS to dynamically retrieve data.
Implement pagination display of tag document list.
To enable pagination for the tag document list, the core lies intagDataListlabel'stypeparameters and then using them in conjunctionpagination.
Firstly, we need to utilizetagDataListtags to retrieve document data under specific tags. In the default tag document list template filetag/list.html,tagDataListThe tag will automatically identify the tag ID of the current page. To enable pagination, we need to settypethe parameter to"page", and uselimitThe parameter defines the number of documents displayed per page, for example, set tolimit="10"Indicates that 10 documents are displayed per page.
OncetagDataListSet to pagination mode, we can introduce the powerful features of AnQiCMS.paginationTags to render page numbers.paginationThe tag automatically calculates the total number of pages, current page number, generates the first page, last page, previous page, next page, and links to the middle page numbers, and can be controlled by parametersshowThe parameter controls the number of middle page numbers, for exampleshow="5"It will display the two pages before and after the current page, with a total of up to five page numbers.
The following is an example of a template code for implementing pagination display:
{# tag/list.html 模板文件示例 #}
<div>
<h1>标签:{% tagDetail with name="Title" %}</h1>
<p>描述:{% tagDetail with name="Description" %}</p>
{% tagDataList archives with type="page" limit="10" %}
{# 循环展示当前页的文档列表 #}
{% for item in archives %}
<li>
<a href="{{item.Link}}">
<h5>{{item.Title}}</h5>
<p>{{item.Description}}</p>
<div>
<span>分类:{% categoryDetail with name="Title" id=item.CategoryId %}</span>
<span>发布时间:{{stampToDate(item.CreatedTime, "2006-01-02")}}</span>
<span>浏览量:{{item.Views}} 阅读</span>
</div>
</a>
{% if item.Thumb %}
<a href="{{item.Link}}">
<img alt="{{item.Title}}" src="{{item.Thumb}}">
</a>
{% endif %}
</li>
{% empty %}
<li>
该标签下暂无任何文档。
</li>
{% endfor %}
{% endtagDataList %}
{# 分页代码区域 #}
<div class="pagination-container">
{% pagination pages with show="5" %}
<ul>
{# 首页链接,如果当前是首页则添加active类 #}
<li class="{% if pages.FirstPage.IsCurrent %}active{% endif %}">
<a href="{{pages.FirstPage.Link}}">{{pages.FirstPage.Name}}</a>
</li>
{# 上一页链接,如果存在则显示 #}
{% if pages.PrevPage %}
<li><a href="{{pages.PrevPage.Link}}">{{pages.PrevPage.Name}}</a></li>
{% endif %}
{# 中间页码,循环展示 #}
{% for item in pages.Pages %}
<li class="{% if item.IsCurrent %}active{% endif %}">
<a href="{{item.Link}}">{{item.Name}}</a>
</li>
{% endfor %}
{# 下一页链接,如果存在则显示 #}
{% if pages.NextPage %}
<li><a href="{{pages.NextPage.Link}}">{{pages.NextPage.Name}}</a></li>
{% endif %}
{# 尾页链接 #}
<li class="{% if pages.LastPage.IsCurrent %}active{% endif %}">
<a href="{{pages.LastPage.Link}}">{{pages.LastPage.Name}}</a>
</li>
{# 还可以显示总数、当前页等信息,例如: #}
<li class="info">共 {{pages.TotalItems}} 条,{{pages.CurrentPage}}/{{pages.TotalPages}} 页</li>
</ul>
{% endpagination %}
</div>
</div>
In this example, we first usetagDetailThe tag retrieves the title and description of the current tag and then throughtagDataListGet the document list and enable pagination.forLoop througharchivesA variable is used to display each document,paginationThe tag is responsible for generating and rendering a beautiful and functional pagination navigation.
Optimize the sorting of the tag document list
In addition to pagination, users often also hope that the content can be sorted according to different criteria so that they can find the information they are interested in more quickly.tagDataListtags provide flexibleorderParameters, allow us to sort in ascending or descending order based on multiple fields.
Common sorting methods include:
- Descending by ID (
order="id desc")This usually indicates that the documents are arranged in the order of the latest publishing time, with the most recently published documents displayed at the top. - Sorted by view count in descending order (
order="views desc")This will be sorted according to the document's reading volume, with the most popular and most read documents displayed first. - Sort by backend custom sorting (
order="sort desc")If the background content management has set a manual sorting field for documents, this option can display content according to the operator's preset order, which is very suitable for精品推荐or special topic display.
We can combineorderParameters are directly added totagDataListthe tag, for example, if you want to sort the tag document list by the latest release time, you can set it like this:
{% tagDataList archives with type="page" limit="10" order="id desc" %}
{# 文档列表内容 #}
{% endtagDataList %}
If you want to display the most popular documents, you can change it to:
{% tagDataList archives with type="page" limit="10" order="views desc" %}
{# 文档列表内容 #}
{% endtagDataList %}
Practical skills and advantages of AnQiCMS
Combining pagination and sorting features, we can provide users with a highly controllable and smooth tag document browsing page. For example, intag/list.htmlBy default, it can be sorted by the most recent release (id descDisplay pages in this manner. If you need to provide users with options to switch sorting methods, you can add some links or buttons on the page, by modifying the query parameters of the URL (for example?order=views_descAdjust dynamicallytagDataListoforderParameter.
AnQiCMS demonstrated its powerful advantages as an enterprise-level CMS in this process:
- Highly customizableThe flexibility of template tags allows developers and operators to fully customize the content display logic according to business requirements, whether it is sorting, pagination style, or the presentation of document content, it can be easily realized.
- SEO-friendly: Generate friendly URLs for tabs through pseudo-static rules, combined with pagination and sorting functions, which helps search engines better crawl and index the content under the tabs, enhancing the overall SEO performance of the website.
- Enhancing user experience: Clear label classification, efficient document list browsing (via pagination), and personalized sorting options greatly enhance the efficiency and satisfaction of users in finding information on the website.
- Lightweight and EfficientBased on Go language development, AnQiCMS can maintain excellent performance and response speed even when processing a large amount of tag and document data, ensuring a smooth user experience.
By these features, Anqi CMS not only simplifies content management, but also empowers operators to achieve better results in content marketing and user growth.
Frequently Asked Questions (FAQ)
Q1: How to display the current tag name and description on the tag page?
A1:In the tag document list page (for exampletag/list.html), you can use it directly.tagDetailTo get the details of the current tag. For example, to display the tag title, you can use{% tagDetail with name="Title" %}; To display the tag description, use{% tagDetail with name="Description" %}These tags will automatically identify the tag ID of the current page and output the corresponding content.
Q2: Why isn't my tag document list properly paginated, or why are the pagination links not working?
A2:Please checktagDataListWhether the tag willtypeSet the parameters correctly to"page"for example{% tagDataList archives with type="page" limit="10" %})。Only when set to"page"The mode,paginationLabels can retrieve the correct pagination data and generate usable pagination links. At the same time, ensure that your template also includes the complete{% pagination pages with show="X" %}...{% endpagination %}code block to render page numbers.
Q3: Can I customize the URL structure of the tag document list, such as including the tag name instead of the ID?
A3:Can be. AnQiCMS supports flexible pseudo-static (URL rewrite) rule configuration. You can manage it in the background's