How to display the link to the previous and next article on the article detail page in AnQiCMS template?

Calendar 👁️ 65

In AnQiCMS, adding 'Previous Article' and 'Next Article' navigation links to the article detail page is a key factor in improving user experience and guiding users to delve deeper into the website content.The powerful template system of AnQiCMS makes this feature very intuitive and efficient, it adopts syntax similar to the Django template engine, allowing developers to easily handle it.

AnQiCMS template files are usually named with.htmlStored as a suffix,/templateUnder the directory. In these template files, we can call and display data using specific tags. Logical control (such as conditional judgment, loop) uses{% ... %}tags, and variable output is used.{{ ... }}Double curly braces. Understanding these basics, we can better utilize the tags provided by AnQiCMS to achieve the desired functions.

Core Tag Introduction:prevArchiveandnextArchive

To display the links to the previous and next articles on the article detail page, AnQiCMS has specially provided two core tags:prevArchiveandnextArchiveThe function of these is to get the data of the previous and next articles of the current article.These tags do not require additional parameters when used, the system will automatically find the adjacent articles in the database based on the article being viewed.

prevArchiveThe tag will assign the data of the previous article to a specified variable, for exampleprev),whilenextArchiveThe tag will assign the data of the next article to another specified variable, for examplenextThese variables contain rich article information, commonly used fields include:

  • Id: The unique ID of the article
  • Title: Article title
  • Link: Article detail page link
  • Description: Article Summary
  • Thumb: Article Thumbnail
  • CreatedTime: The article publication time (timestamp format, which needs to be配合stampToDateTag Formatting)
  • Views: Article views

Actual operation: Add link to article details page

Add links to the previous and next articles in the template of the article detail page, you usually find a suitable position below the article content. Assuming your article detail page template isarticle/detail.htmlOr a similar path, you can follow the following steps:

1. Basic link implementation

First, you need to useprevArchiveandnextArchiveLabel to get adjacent article data and determine if it exists. If it exists, display the link; if not, you can display a prompt message.

<div class="article-pagination">
    <div class="prev-article">
        {%- prevArchive prev %} {# 获取上一篇文章数据,赋值给变量prev #}
            {%- if prev %} {# 判断是否存在上一篇文章 #}
                <a href="{{ prev.Link }}" title="上一篇:{{ prev.Title }}">上一篇:{{ prev.Title }}</a>
            {%- else %}
                <span class="no-link">没有上一篇文章了</span>
            {%- endif %}
        {%- endprevArchive %}
    </div>
    <div class="next-article">
        {%- nextArchive next %} {# 获取下一篇文章数据,赋值给变量next #}
            {%- if next %} {# 判断是否存在下一篇文章 #}
                <a href="{{ next.Link }}" title="下一篇:{{ next.Title }}">下一篇:{{ next.Title }}</a>
            {%- else %}
                <span class="no-link">没有下一篇文章了</span>
            {%- endif %}
        {%- endnextArchive %}
    </div>
</div>

We used here{%- ... %}syntax, among which the-The symbol is used to remove the whitespace that may be generated by the tag line itself, making the final rendered HTML cleaner.

2. Enrich the display content of links (optional)

In addition to the title, you can also add thumbnails or article summaries to the link as needed to make navigation more intuitive. For example, you can add a thumbnail and a summarized excerpt to the link:

<div class="article-pagination">
    <div class="prev-article">
        {%- prevArchive prev %}
            {%- if prev %}
                <a href="{{ prev.Link }}" title="上一篇:{{ prev.Title }}" class="pagination-link">
                    {%- if prev.Thumb %}<img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="pagination-thumb" />{%- endif %}
                    <div class="link-content">
                        <span class="link-label">上一篇</span>
                        <h4 class="link-title">{{ prev.Title }}</h4>
                        {%- if prev.Description %}<p class="link-desc">{{ prev.Description|truncatechars:50 }}</p>{%- endif %}
                    </div>
                </a>
            {%- else %}
                <span class="no-link">没有上一篇文章了</span>
            {%- endif %}
        {%- endprevArchive %}
    </div>
    <div class="next-article">
        {%- nextArchive next %}
            {%- if next %}
                <a href="{{ next.Link }}" title="下一篇:{{ next.Title }}" class="pagination-link">
                    <div class="link-content">
                        <span class="link-label">下一篇</span>
                        <h4 class="link-title">{{ next.Title }}</h4>
                        {%- if next.Description %}<p class="link-desc">{{ next.Description|truncatechars:50 }}</p>{%- endif %}
                    </div>
                    {%- if next.Thumb %}<img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="pagination-thumb" />{%- endif %}
                </a>
            {%- else %}
                <span class="no-link">没有下一篇文章了</span>
            {%- endif %}
        {%- endnextArchive %}
    </div>
</div>

In this example, we addedprev.Thumb

Related articles

How to integrate MathJax or Mermaid.js in AnQiCMS page to display mathematical formulas and flowcharts?

Integrate MathJax and Mermaid.js on AnQiCMS page: Easily display mathematical formulas and flowcharts AnQiCMS is an efficient and flexible content management system that excels in meeting various content display requirements.With the increasing richness of technical content, many users may encounter the need to elegantly display mathematical formulas and flowcharts on websites.AnQiCMS integrates its built-in Markdown editor and flexible template support, allowing integration with MathJax and Mermaid.js

2025-11-09

How to implement nested display of multi-level category navigation with the `categoryList` tag in AnQiCMS?

When building a website with comprehensive functionality, a clear and easy-to-navigate category system is the key to improving user experience and optimizing content structure.AnQiCMS as an efficient enterprise-level content management system provides flexible template tags to meet diverse content display needs.Among them, the `categoryList` tag is the core tool for achieving nested display of multi-level classification navigation.

2025-11-09

How to get and display the extended fields of a custom content model in the AnQiCMS template?

Flexibly obtain and display extended fields of custom content models in the AnQiCMS template, which is the key to achieving personalized content display on the website.AnQiCMS powerful content model customization capabilities, allowing us to add various unique attributes to articles, products, and other content according to actual business needs, and how to present these customized data beautifully in the frontend template is exactly the topic we are going to delve into today.### The Flexibility of AnQiCMS Content Model AnQiCMS is an enterprise-level content management system developed based on the Go language

2025-11-09

How to implement lazy loading of images in document content in AnQiCMS to improve page loading speed?

In website operation, page loading speed is always one of the key factors affecting user experience and search engine optimization (SEO).Especially for websites with rich content, images are often the main factor that slows down page speed.Therefore, how to efficiently manage image resources has become an indispensable factor in improving website performance.Today, let's talk about how AnQiCMS cleverly implements lazy loading of images in document content, thus significantly improving page access speed.In AnQiCMS's design philosophy, website performance optimization is one of its core advantages.

2025-11-09

How to call and display the contact information set in the background of the AnQiCMS website at the bottom, such as phone number, email?

Clearly display contact information at the bottom of the website, which is crucial for improving user experience and building trust.AnQiCMS as an efficient content management system takes this into full consideration, providing an intuitive and flexible way to manage and display this key information, such as phone numbers and email addresses. ### One, AnQiCMS backend contact settings and management In the AnQiCMS backend management interface, you can easily find and configure the website's contact information.

2025-11-09

How to implement dynamic display and link jump of the website homepage Banner carousel in AnQiCMS?

In website operation, an attractive homepage banner carousel is a key element to enhance user experience, highlight core content, and guide user behavior.AnQiCMS as an efficient and flexible content management system provides an intuitive way to manage and display these dynamic contents.Next, we will explore how to easily implement the dynamic display and link jump of the website homepage Banner slideshow using AnQiCMS.

2025-11-09

How to truncate article content in AnQiCMS template and display “...”?

How to elegantly truncate article content and display "..." in the AnQiCMS template?In website content operation, we often need to display the summary of articles, products, or single-page content on list pages, aggregation pages, or search results.These summaries not only make the page look neater, but also help visitors quickly understand the content outline, so that they can decide whether to click to read the full text.

2025-11-09

How does AnQiCMS ensure that each site's page content is displayed independently under multi-site management?

AnQiCMS was designed from the beginning to fully consider the needs of enterprises and content operators for multi-site management and is committed to providing a highly efficient and independent solution.When you create multiple sites in AnQiCMS, the system ensures that the page content of each site can be displayed independently, without interference, and also allows for limited cross-site content interaction when needed.

2025-11-09