In content operation, providing navigation to the previous and next articles for each article can not only significantly improve the user's reading experience, but also effectively increase the internal links of the website, which is of great benefit to search engine optimization (SEO).AnQi CMS with its flexible template system makes the implementation of this feature intuitive and efficient.By using a brief template tag, you can easily integrate this practical navigation mechanism on the article detail page.
Core Function Analysis: Tags of previous and next documents
The AnQi CMS is built-in with special template tags for retrieving the previous and next articles of the current article, respectivelyprevArchiveandnextArchiveThese tags are intended to be used on the article detail page, the system will automatically identify and provide data for adjacent articles based on the current article's order in the list.
They use a very simple method, do not require complex parameter settings, just define a variable name within the tag to carry the data. For example, you can use{% prevArchive prev %}To get information about the previous article, and byprevthis variable to access its data; similarly,{% nextArchive next %}is used to get information about the next article, bynextvariable to operate.
Once defined,prevornextSuch a variable, we can pass through{{变量名.字段名}}In the form to access the various information of the previous or next article
Variables and available fields inside the tag
InprevandnextIn the variable, AnQi CMS provides a rich set of article-related fields, which you can flexibly call according to your template design requirements. Some of the most commonly used fields include:
- Document title (
Title)Description: Used to display the article name. - Document link (
Link)Description: Used to generate clickable navigation links. - Document cover thumbnail (
Thumb): If your design needs to display a preview of the previous or next article, this field is very useful.
Of course, you can also access other fields, such asId(Document ID),Description(Document Description),CategoryId(Document Category ID),Views(Document Views) evenCreatedTime(Article Publish Time). For time fields, if formatting is required, it can be配合stampToDateFilter usage, for example{{stampToDate(item.CreatedTime, "2006-01-02")}}.
Actual application: write template code
Now, let's see how to actually write these navigation links in your Anqi CMS template. Usually, this code is placed inarchive/detail.htmlAt the bottom, below the article content of the document details template (or your custom template).
The following is a basic example, it checks for the existence of the previous or next article and displays its title and link:
<nav class="article-pagination">
<div class="prev-article">
{% prevArchive prev %}
{% if prev %}
上一篇:<a href="{{ prev.Link }}">{{ prev.Title }}</a>
{% else %}
<span>没有上一篇文章了</span>
{% endif %}
{% endprevArchive %}
</div>
<div class="next-article">
{% nextArchive next %}
{% if next %}
下一篇:<a href="{{ next.Link }}">{{ next.Title }}</a>
{% else %}
<span>没有下一篇文章了</span>
{% endif %}
{% endnextArchive %}
</div>
</nav>
`twig