How to display the 'Previous' and 'Next' article links and titles on the article detail page?

Calendar 👁️ 72

It is crucial to enhance user experience and content discoverability in website operation.When the reader is immersed in an article, providing 'Previous' and 'Next' navigation links can not only guide them to continue browsing the website content but also effectively reduce the bounce rate and optimize the on-site SEO structure.For those of us using AnQiCMS to manage websites, implementing this feature is both simple and efficient.

AnQiCMS provides a直观and powerful template tag system, making it easy to integrate "previous article" and "next article" links on the article detail page.We do not need complex programming knowledge, just add a few lines of code to the corresponding template file.

Core Tag Introduction:prevArchiveandnextArchive

To display navigation on the article detail page, AnQiCMS has specially provided two template tags:

  • prevArchive: It is used to get the data of the previous article of the current article.
  • nextArchiveGet the data for the next article of the current article.

These tags will automatically find and provide information about adjacent articles based on the sorting position of the current article in the category. It should be noted that not every article has a previous or next article (for example, the first article in a series does not have a previous article, and the last article does not have a next article), so we need to use conditional judgment tags when using them{% if %}Ensure that links are displayed only when data exists, to avoid displaying empty links or errors on the page.

Locate the article detail page template

To implement this feature, we first need to find the template file of the website's article detail page. According to the template convention of AnQiCMS, the template of the article detail page is usually located in the template directory.{模型table}/detail.htmlFor examplearticle/detail.htmlorproduct/detail.htmlIf you have used a custom template, you need to find the corresponding file you have configured for the article details.

Specific implementation steps: Add navigation links and titles.

After finding the correct template file, we can add the following code at the end of the article content (usually below the article text, above the comments section, or next to related article recommendations).This code intelligently determines whether there is a previous or next article and displays its title and link.

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %}
        {% if prev %}
            <span>上一篇:</span>
            <a href="{{ prev.Link }}">{{ prev.Title }}</a>
        {% else %}
            <span>上一篇:没有了</span>
        {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-article">
        {% nextArchive next %}
        {% if next %}
            <span>下一篇:</span>
            <a href="{{ next.Link }}">{{ next.Title }}</a>
        {% else %}
            <span>下一篇:没有了</span>
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

In this code block:

  • We use{% prevArchive prev %}and{% nextArchive next %}To declare a tag to retrieve the data of the previous and next articles and store them separatelyprevandnextthe variable.
  • Then, use{% if prev %}or{% if next %}to determine whether these variables have actual content
  • If they exist, proceed through{{ prev.Link }}and{{ prev.Title }}(ornextVariable corresponds to the field to output the article link and title.
  • If it does not exist, we will display a friendly prompt text, such as 'None', which can enhance user experience.

Advanced usage: Introduce thumbnails to enhance visual appeal

If you want the navigation links to be more attractive, we can also consider adding a thumbnail next to the links.prevArchiveandnextArchiveData retrieved from the tag, excludingLinkandTitleusually also includesThumb(thumbnail) orLogo(Cover main image) and other fields.

Can be modified based on the above code:

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}">
                {% if prev.Thumb %}
                    <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" />
                {% endif %}
                <span>上一篇:{{ prev.Title }}</span>
            </a>
        {% else %}
            <span>上一篇:没有了</span>
        {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-article">
        {% nextArchive next %}
        {% if next %}
            <a href="{{ next.Link }}">
                <span>下一篇:{{ next.Title }}</span>
                {% if next.Thumb %}
                    <img src="{{ next.Thumb }}" alt="{{ next.Title }}" />
                {% endif %}
            </a>
        {% else %}
            <span>下一篇:没有了</span>
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

Here we added one.{% if prev.Thumb %}(ornext.ThumbThe judgment should ensure that the image is displayed only when the thumbnail exists, and link it to the article.The final style can be beautified with external CSS to make it more in line with the overall design of the website.

Consideration of placement and style.

We usually place these navigation links at the end of the article content, such as between the main text and the comments section, or next to related recommended articles.After reading the current content, the reader can naturally discover and click to go to the next article.

As for the final style of these links, it needs to be beautified through CSS.For example, you can set their layout (floating left or right or stacking vertically), font size, color, background color, and animation effects on mouse hover, etc., to ensure they are both aesthetically pleasing and easy to click.

Check and Test

After modifying the code, remember to save the template file and clear the cache in the AnQiCMS backend (if your system has cache enabled).Then, visit the article detail page of your website and test different articles (such as the first article, middle article, and last article) to ensure that the 'Previous' and 'Next' links display and jump correctly.

By following these steps, we can easily provide readers with a smooth "previous" and "next" navigation experience on the article detail page of the website built with AnQiCMS.


Frequently Asked Questions (FAQ)

1. Why did I add the 'Previous' and 'Next' code, but the page only displays 'None' or does not display any content?This is usually because the article you are currently browsing is indeed the first in the category (with no previous one) or the last (with no next one). If all articles show 'No more', please check if your template tags are spelled correctly, as well asprevArchiveandnextArchiveIs the label properly placed in the article detail page template. Moreover, make sure that your article is indeed categorized and that there are multiple articles under the category.

2. What is the rule for sorting the links of 'Previous' and 'Next'? Can the sorting rule be customized? prevArchiveandnextArchiveTags are usually automatically determined based on the publication time of the article (the latest is the next one, and the oldest is the previous one) or the ID order (the larger the ID, the later it is).Currently, these two tags built into AnQiCMS do not provide custom sorting parameters directly.If you need a more complex sorting logic, you may consider usingarchiveListTags combined with customizationlimitandorderA parameter, and to simulate the effect of 'Previous/Next' by programming logic, this will be more complex than usingprevArchiveandnextArchiveit directly.

3. Can I only display the link and title, and not show the 'No more' prompt text?Can. If you do not want to display any prompt text when there is no previous or next article, just{% else %}delete the code block and its content. For example,{% else %}<span>上一篇:没有了</span>{% endif %}Delete, so that this area will be blank when there is no previous one.

Related articles

How to call and display the custom fields of an article on the article detail page?

In Anqi CMS, the content display of the article detail page is highly flexible, especially for fields customized through the content model.These custom fields can help us manage and display different types of information more precisely, such as product prices, authors' origins, and property layouts, etc.How can you accurately call and display the content of these custom fields on the article detail page?This article will introduce this process in detail. ### 1. Custom field creation and filling: laying the content foundation In AnQi CMS

2025-11-08

How to display a list of related articles based on the keywords or custom associations of an article?

In website content operation, providing users with a list of relevant articles can not only effectively extend the visitor's stay time on the website and reduce the bounce rate, but also through guiding users to discover more interesting content, optimize the internal traffic path, and have a positive impact on SEO performance.AnQiCMS (AnQiCMS) understands this need and provides flexible and powerful functions, allowing us to easily display lists of related articles based on keywords or custom associations.###

2025-11-08

What sorting and filtering options does AnQiCMS provide to control the display order of list content?

How to efficiently display and organize content in website operation directly affects the user experience and the efficiency of information transmission.For users who use AnQiCMS, the system provides various flexible sorting and filtering options to help us accurately control the display order of list content. Whether it is articles, products, or other custom content types, they can be presented to visitors in the most business-friendly way possible.The AnQi CMS has given the control of content display order to the user, which is mainly realized through a powerful template tag system and backend management settings.Through these features

2025-11-08

How can you list the latest articles or products under a specified category in AnQiCMS?

Manage website content in AnQiCMS, often need to display relevant information according to different themes or sections.For example, you may want to display the latest articles under the "Company News" category in some area of the homepage, or show the latest products under the "Hot New Products" category in the sidebar of the product page.AnQiCMS provides flexible and powerful template tags, allowing you to easily implement these content call requirements.Understanding the content organization of AnQiCMS is the key to efficiently utilizing its features.The system distinguishes different types of content through the "content model", such as article models and product models

2025-11-08

How can I build and display a multi-level nested category navigation menu?

Building and displaying multi-level nested category navigation menus in Anqi CMS is an important aspect of website content organization and user experience optimization.A well-designed, hierarchical navigation not only helps visitors quickly find the information they need, but also provides clear website structure signals to search engines, thereby improving SEO effectiveness. AnQi CMS is an enterprise-level content management system developed in Go language, with flexible content models and powerful template tags, making it very intuitive and efficient to implement multi-level classification navigation.Next, we will explore how to step by step build such navigation

2025-11-08

How to display the top-level category list of a specific content model on the homepage or sidebar?

In AnQi CMS, managing website content, we sometimes need to clearly display the top-level category list of a specific content model at key positions such as the homepage or sidebar.This not only effectively guides visitors to browse the website content and improve user experience, but is also an important aspect of website content architecture optimization and search engine friendliness.Using AnQiCMS's flexible template system and powerful tag features, it is direct and efficient to meet this requirement. ### Understanding the Core: Content Model and Classification The core of content management in Anqi CMS lies in the "content model".You can create different content models based on business requirements

2025-11-08

How to create and display single-page content such as “About Us” and “Contact Us”?

In website operation, single-page content like "About Us", "Contact Us", and the like are windows to showcase the corporate image, core values, or provide key information to visitors.They usually carry stable, independent and infrequent updated content, which is crucial for building trust and providing service access.AnQiCMS provides very convenient and powerful functions for managing and displaying these single-page applications, allowing you to easily create and customize them.### Part 1: Create Your Single Page Content Creating a single page in AnQiCMS is an intuitive and efficient process

2025-11-08

How to display all used Tag tags on the website or only display Tag tags related to the current article in AnQiCMS?

When building website content, tags play an important role. They can not only help you better organize information and improve the discoverability of content, but also optimize the user experience, making it easier for visitors to find the content they are interested in.For a content management system, flexibly displaying and managing these tags is one of its core values.AnQiCMS provides powerful functions in this aspect, allowing you to easily control the display of tags on your website according to your actual needs.### Add and manage Tag tags On AnQiCMS backend

2025-11-08