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

Calendar 👁️ 72

On the article detail page of AnQi CMS, displaying "Previous" and "Next" navigation links is an important aspect for enhancing user reading experience and the internal link structure of the website.This not only guides readers to continue browsing related content, extends user stay time, but also helps search engines better understand the relevance of website content, and has a positive effect on SEO optimization.

AnQi CMS provides a user-friendly and powerful template tag system, which includes a special tag for fetching adjacent articles.prevArchiveand the previous document"),nextArchive(Next document) tag. By simply adding these tags in the article detail page template, we can easily achieve this function.

Understand the 'Previous/Next' tag of AnQi CMS

The template tag design of AnQi CMS is aimed at simplifying content calls.prevArchiveandnextArchiveThese tags are specifically designed for article detail pages, capable of automatically identifying the current article and searching for the previous or next article with the same content model, sorted by publication time.

These tags, when called, will return an object containing detailed information about adjacent articles, from which we can extract the title of the article (",Title) and link (Link), even thumbnail (",Thumb) and other fields to construct links.

Core step: Add tags to the template file

To implement this feature on your website, you first need to edit the article detail page template file. As a rule, the article detail page template file is usually named{模型table}/detail.htmlFor example, if it is an article model, it may bearchive/detail.html. You can also find the custom article detail page template according to the content model settings on the backend.

We will show you how to add these links in two steps, from basic text links to richer text and image links.

Step one: Basic text link

In your article detail page template, find the location where you want to display the "Previous" and "Next" links, which is usually below the article content. Then, you can add the following code:

<div class="article-navigation">
    {# 上一篇链接 #}
    <div class="prev-article">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="{{ prev.Title }}">« 上一篇:{{ prev.Title }}</a>
            {% else %}
                <span>« 没有上一篇了</span> {# 如果没有上一篇,显示提示文字 #}
            {% endif %}
        {% endprevArchive %}
    </div>

    {# 下一篇链接 #}
    <div class="next-article">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }}">下一篇:{{ next.Title }} »</a>
            {% else %}
                <span>没有下一篇了 »</span> {# 如果没有下一篇,显示提示文字 #}
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

Code analysis:

  • {% prevArchive prev %}This is a label that calls the previous document. It assigns the information of the previous article to a nameprev.
  • {% nextArchive next %}Similarly, this label assigns the information of the next article to a namenext.
  • {% if prev %}and{% if next %}This is a very important conditional judgment. If the current article is the first in its category, then there is no previous one;If it is the last one, there will be no next one. In this case, the correspondingprevornextThe variable will be empty. Through this judgment, we can avoid displaying empty links and provide friendly prompts, such as 'No previous article'.
  • {{ prev.Link }}and{{ prev.Title }}:prevandnextThe variable is an object, we can go through.Visit their properties, such as the link and title of the article.

Step 2: Enhanced image and text link

If you want these navigation links to be more attractive, consider adding a thumbnail of the article. From Anqi CMS.prevArchiveandnextArchiveTags also providedThumb(thumbnail) field.

In the template, you can modify the code like this:

<div class="article-navigation-enhanced">
    {# 上一篇 #}
    <div class="nav-item prev-item">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                    {% if prev.Thumb %}
                        <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="nav-thumb"/>
                    {% endif %}
                    <p class="nav-label">« 上一篇</p>
                    <h3 class="nav-title">{{ prev.Title }}</h3>
                </a>
            {% else %}
                <span class="no-nav">« 没有上一篇了</span>
            {% endif %}
        {% endprevArchive %}
    </div>

    {# 下一篇 #}
    <div class="nav-item next-item">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }}">
                    {% if next.Thumb %}
                        <img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="nav-thumb"/>
                    {% endif %}
                    <p class="nav-label">下一篇 »</p>
                    <h3 class="nav-title">{{ next.Title }}</h3>
                </a>
            {% else %}
                <span class="no-nav">没有下一篇了 »</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

Code enhancement points:

  • {% if prev.Thumb %}: Similarly, we have made a judgment about the existence of thumbnails, in case some articles have not set thumbnails.
  • imgLabel: Use{{ prev.Thumb }}to display thumbnails and matchaltproperties to enhance SEO friendliness.
  • pandh3Label: Wrap the navigation text in semantically meaningful tags and add CSS classes for easy styling and beautification.

After adding the code, please make sure to upload the modified template file to your AnQiCMS system and refresh the page by using the 'Update Cache' feature in the background.Next, you may need to adjust the layout, color, and font of these links through CSS styles to keep them consistent with your website design.

Summary

Provided by AnQiCMSprevArchiveandnextArchiveTemplate tags, you can add navigation links to the previous and next articles on the article detail page very flexibly.This can optimize the browsing path of users on the website, reduce the bounce rate, and also effectively enhance the internal link structure of the website, providing a clearer website content map for search engines.

Frequently Asked Questions (FAQ)

Why did I add the code but the previous/next link did not display on the page?Answer: First, please check if your code has been saved and uploaded to the corresponding article detail page template file of Anqi CMS (for examplearchive/detail.htmlNext, confirm whether the current article has adjacent articles: if it is the first or last article in the category, then the corresponding 'previous' or 'next' link will not be displayed.At the same time, updating the system cache is also a necessary step.

Ask: What is the sorting rule of these links? Are they random?Answer: They are not random. Anqi CMS will sort articles based on the fields under the same category in theRelease Time(CreatedTimefield) for sorting.prevArchiveThe tag will find the closest article published before the current article, andnextArchiveThe tag will find the closest article published after the current article, and

Can I change the prompt text of 'No previous article' or 'No next article'?Of course, you can. In the above example code,<span>« 没有上一篇了</span>and<span>没有下一篇了 »</span>This text can be freely edited and replaced. You can change it according to the context of the website

Related articles

How to call and display a document list in a template, and perform sorting and filtering?

Manage and display website content in AnQi CMS, especially document lists, is a very common need in daily operation.Strong and flexible template tags provided by AnQi CMS, allowing us to easily call and display this content on the website front-end, and sort and filter as needed.This article will deeply explore how to use the template function of Anqi CMS to achieve these goals and make your website content display more attractive.### Core Function: `archiveList` tag - Display the basic document content To display the document list

2025-11-08

How to retrieve and display the complete content and images of a specific single page?

Use AnQiCMS to manage and display website content, especially when dealing with independent and rich single-page content such as "About Us" and "Contact Information", its flexibility and powerful functions are particularly prominent.We often need to present the text, images, and even image sets of these pages in their entirety on the website, and AnQiCMS provides a very intuitive way to achieve this. Let's explore together how to retrieve and display the complete content and images of a specific single page in AnQiCMS, making your website content more vivid and diverse.## Content Creation

2025-11-08

How to list and display the titles and links of all single pages?

AnQi CMS provides a user-friendly and powerful content management system, where the single-page feature is an ideal choice for building independent pages such as "About Us", "Contact Information", or "Privacy Policy".When you need to display the titles and links of these single-page in a centralized position on the website, such as in the footer navigation, sidebar, or a dedicated page index, the template tags of AnQiCMS can help you easily achieve this.In the AnQiCMS backend, single-page content is created and maintained under "Page Resources" > "Page Management".You can easily add to the website like 'About Us'

2025-11-08

How to retrieve and display detailed information for a specific category, such as the category logo and introduction?

In website operation, a clear and informative classification display is the key to attracting visitors, improving user experience, and optimizing search engine rankings.AnQiCMS provides a user-friendly and powerful template tag system that allows you to flexibly obtain and display detailed information of various categories on your website, such as category logo and introduction, thereby creating a more attractive content layout. ### Understand Category Information Management and Configuration Category information management is very convenient in the Anqi CMS backend.When you enter the 'Content Management' under 'Document Category' to add or edit

2025-11-08

How to get and display a list of recommended articles related to the current article?

In website operation, when we have worked hard to create an article, we naturally hope that it can be seen by more readers and guide them to explore more exciting content.On the bottom or sidebar of the article detail page, cleverly display recommended content related to the current article, which can not only significantly improve the depth and dwell time of users' reading, but also bring many benefits to search engine optimization (SEO).AnQiCMS (AnQiCMS) fully understands this need and provides extremely convenient and powerful tags to help us easily achieve this goal.### Cleverly Utilize `archiveList`

2025-11-08

How to display the content of custom fields (such as author, source) on the article detail page?

In website operation, the article detail page is not only a place to display the core content, but also a key to convey additional information, enhance professionalism, and improve user experience.In addition to the title and body, we often need to display some custom fields on the article detail page, such as author, source, publisher, product model, and so on.This information not only enriches the content of the article, but also helps to enhance the authority and credibility of the website, even having a positive impact on SEO optimization and user decision-making.AnQiCMS (AnQiCMS) is designed with a flexible content model, making the display of these custom fields very intuitive and powerful

2025-11-08

How to use Tag tags to associate and display related content on the front end?

In Anqi CMS, content organization and association is the key to enhancing website value, optimizing user experience, and improving search engine performance.In addition to the traditional classification structure, we also have a very powerful and flexible tool - Tag tag.It is like a 'living index' of content, which helps us to connect scattered content in multiple dimensions, making it easier for users to find the information they are interested in.Today, let's talk about how to make full use of Tag tags on the front end to associate and display our wonderful content.### Tag label: Flexible content association bridge Different from a strict classification system

2025-11-08

How to implement the pagination display function of the article comment list?

In website operation, effectively managing and displaying user comments is crucial for enhancing user interaction and content vitality.AnQiCMS (AnQiCMS) is a powerful content management system that provides flexible template tags, allowing us to easily implement pagination display of article comment lists.This article will introduce in detail how to implement this feature through template tags in Anqi CMS, thus providing users with a better browsing experience.Understanding the core of comments and pagination In the Anqi CMS template system, implementing pagination display of article comment lists

2025-11-08