As a senior website operations expert, and with a deep understanding of all the functions of AnQiCMS (AnQiCMS), I often encounter users who have questions about the behavior of certain tags during template development. Today, let's discuss a very classic and practical question: "IfarchiveListThe returned data is less thanlimit,paginationWill the tag still display? This question concerns the elegance of page layout, the fluidity of user experience, and potential SEO optimization.
An enterprise CMS that offers great convenience for content management with its concise and efficient architecture and flexible and powerful template engine. In its template system,archiveListTags are used to retrieve document lists, andpaginationare responsible for generating page navigation. Both of these usually work together, especially when displaying paginated document content.
UnderstandingarchiveListWithpaginationThe mechanism of the English
Firstly, let's briefly review the basic functions of these two tags.
archiveListLabels are your tool for extracting lists of articles, products, or any other content based on models from the database. It has many parameters, such ascategoryId(filtered by category),order(Sort method), as well as the focus of our attention todaylimit(Number of items per page) andtype(List type, it can be)listorpage). Whentypeis set to"page"whenarchiveListthe dataset for pagination will be ready, which will be used for subsequentpaginationLabels provide the foundation.
whilepaginationLabels, as the name suggests, are used to render page navigation controls. It receives one generated byarchiveList(or other pagination data sources)pagesObject, and according to the information contained in this object, such as total number of pages, current page, previous page, next page, and so on, to build the familiar page number links that we are familiar with.
Insufficient data volumelimitwhenpaginationBehavior analysis of tags
Now let's go back to our core issue: whenarchiveListTagged throughtype="page"Pattern retrieves data. If the actual number of documents returned is not enough to fill a page (i.e., less thanlimitthe value set by the parameter),paginationwill the tag still be displayed?
The answer is:paginationThe label itself will still be processed and parsed by the template engine, but whether the final visual output, or whether visible page navigation will be rendered on the page, depends on how the template developer writes the logical judgment.
AnQiCMS's template engine in processingarchiveList type="page"When processing, even if the amount of data is small, it will generate a completepagespagination object. Thispagesobject includes such asTotalItems(total number of entries),TotalPages(Total number of pages),CurrentPage(Current page)et other key information. When the returned data is insufficientlimitwhenTotalItemsit will be the actual amount of data, whereasTotalPagesit will be calculated as1.
This means, even if there are only 5 articles, and you have setlimit="10",paginationLabel will still receive onepagesof the object,TotalPagesThe value is1. If your template code does not make any judgments, it outputs directlypaginationThe content of the label may render a page number that shows only 'Page 1/Total 1' or just '1', or may not display anything at all (this depends on the design of the default template).
**Practice: Optimizing User Experience with Conditional Judgment
To provide a **good user experience and page cleanliness, we do not want to display redundant page navigation when there is only one page of content. Therefore, as an experienced website operator, you should skillfully use conditional judgment in your template.paginationThe display of labels.
AnQiCMSpaginationLabels provide a very critical attribute:TotalPages). WhenTotalPagesequals1When this is the case, it means that all content can be displayed on a single page, and there is no need to display pagination navigation.
The following is an example of a recommended template writing logic:
{# 首先,使用 archiveList 标签获取文档列表,并指定 type="page" 来启用分页功能 #}
{% archiveList archives with type="page" limit="10" %}
{# 循环输出文档列表内容 #}
{% for item in archives %}
<div class="article-item">
<h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
<p>{{ item.Description }}</p>
<span>发布日期: {{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
</div>
{% empty %}
<p>当前分类下暂无文章。</p>
{% endfor %}
{% endarchiveList %}
{# 接下来,使用 pagination 标签生成页码导航 #}
{# 关键在于外部的 {% if pages.TotalPages > 1 %} 判断 #}
{% pagination pages with show="5" %}
{% if pages.TotalPages > 1 %} {# 只有当总页数大于1时,才显示分页导航 #}
<div class="pagination-controls">
<ul>
{# 首页 #}
<li class="page-item {% if pages.FirstPage.IsCurrent %}active{% endif %}">
<a href="{{ pages.FirstPage.Link }}">{{ pages.FirstPage.Name }}</a>
</li>
{# 上一页 #}
{% if pages.PrevPage %}
<li class="page-item"><a href="{{ pages.PrevPage.Link }}">{{ pages.PrevPage.Name }}</a></li>
{% endif %}
{# 中间多页 #}
{% for item in pages.Pages %}
<li class="page-item {% if item.IsCurrent %}active{% endif %}">
<a href="{{ item.Link }}">{{ item.Name }}</a>
</li>
{% endfor %}
{# 下一页 #}
{% if pages.NextPage %}
<li class="page-item"><a href="{{ pages.NextPage.Link }}">{{ pages.NextPage.Name }}</a></li>
{% endif %}
{# 尾页 #}
<li class="page-item {% if pages.LastPage.IsCurrent %}active{% endif %}">
<a href="{{ pages.LastPage.Link }}">{{ pages.LastPage.Name }}</a>
</li>
</ul>
<p>总数:{{ pages.TotalItems }}条,共:{{ pages.TotalPages }}页,当前第{{ pages.CurrentPage }}页</p>
</div>
{% endif %}
{% endpagination %}
In the code above,{% if pages.TotalPages > 1 %}You can ensure that the pagination control is rendered only when there is indeed multi-page content to navigate.This not only makes the page look simpler, but also avoids unnecessary interference to the user.
Summary
Anqi CMS'spaginationTags inarchiveListInsufficient return datalimitwill indeed be processed and generated whenpagesHowever, whether the page navigation is actually displayed depends entirely on the conditional logic you add in the template. By thepages.TotalPagesThe check of properties, you can easily implement intelligent pagination display, thus optimizing the user experience, and keeping the website pages neat and professional.
Common Questions (FAQ)
Question: If
archiveListThe returned data is zero,pagination标签还会显示吗?答:不会。当archiveList返回数据为零时,pagination标签生成的pagesthe object ofTotalItems将为0,TotalPages也会是0。根据我们上面介绍的{% if pages.TotalPages > 1 %}Determine whenTotalPagesWhen 0, this condition is not met, so the pagination navigation content will not be rendered.Q: Can I use
type="list"mode'sarchiveListDo you want to generate pagination?Answer: No.archiveListTagstypeThe parameter must be set to ."page"to enable the pagination feature and withpaginationLabel collaboration. If set to"list",archiveListIt will only return a fixed number of entries according to thelimitspecified by the parameters, and will not generate apagespagination object, at this time