How to display "Previous" and "Next" articles on the article detail page to enhance user experience?

Calendar 👁️ 114

In website content operation, continuously optimizing user experience is the key to enhancing website value.How to guide users to discover more related content while browsing an article on your website and maintain their reading interest is a question that every operator needs to think about.Add 'Previous Article' and 'Next Article' navigation at the bottom or side of the article detail page is a very effective and common strategy.It not only allows users to explore the website content more conveniently, reduces the trouble of returning to the list page to search, but also subtly extends the user's stay time on the website, lowers the bounce rate, and helps build a healthy internal link structure for the website, and is also of great benefit to search engine optimization (SEO).

For operators using AnQiCMS (AnQi Content Management System), implementing this feature is quite intuitive and efficient.AnQiCMS with its flexible template tag system allows you to easily customize the website frontend without a deep understanding of complex programming logic.

Detailed steps of implementation

Add 'Previous Article' and 'Next Article' navigation to the article detail page of AnQiCMS, you mainly need to complete the following simple steps:

  1. Locate the article detail page template fileIn AnQiCMS, the detail pages of different content models (such as articles, products, etc.) usually correspond to independent template files.You need to find the detail page template used by the content model of the article you want to add navigation functionality to.These template files are usually located in your theme directory, the path structure is similar to/template/您的模板名称/{模型table}/detail.html. For example, if your website uses a template nameddefaultand the corresponding database table name of the article model isarticleThen the file you need to edit is probably/template/default/article/detail.html. You can directly edit the file online through the "Template Design" feature of the AnQiCMS backend, or download it locally via FTP/SFTP tools for modification.

  2. Understand the core template tagsprevArchiveandnextArchiveAnQiCMS provides two powerful template tags specifically for obtaining adjacent articles on the article detail page:

    • {% prevArchive 变量名称 %}This tag is used to get the information of the previous article of the current article. You need to specify a variable name for it, such asprev), so that the variable can be used in subsequent template code to access various properties of the previous article, such as title, link, etc.
    • {% nextArchive 变量名称 %}: withprevArchiveLabels similar, it is used to get information about the next article of the current article. You can also specify a variable name for it (such asnext). These tags are very easy to use, they do not require any parameters, AnQiCMS will automatically search and provide adjacent article data based on the current context information of the article (such as category, publication time, etc).
  3. Insert navigation code in the templateAfter finding the correct template file, you can insert the following code snippet below the article content, in the sidebar, or at any position you think is appropriate.This code includes judgment logic, it will display the corresponding link only when there is a "Previous" or "Next" article, otherwise it will display a friendly prompt message.

    <div class="article-pagination-nav">
        <div class="prev-article-link">
            {% prevArchive prev %}
            {% if prev %}
                <a href="{{prev.Link}}" title="上一篇:{{prev.Title}}">
                    <span class="nav-direction">&laquo; 上一篇:</span>
                    <span class="nav-title">{{prev.Title}}</span>
                </a>
            {% else %}
                <span class="nav-direction">&laquo; 上一篇:没有了</span>
            {% endif %}
            {% endprevArchive %}
        </div>
        <div class="next-article-link">
            {% nextArchive next %}
            {% if next %}
                <a href="{{next.Link}}" title="下一篇:{{next.Title}}">
                    <span class="nav-direction">下一篇:&raquo;</span>
                    <span class="nav-title">{{next.Title}}</span>
                </a>
            {% else %}
                <span class="nav-direction">下一篇:没有了 &raquo;</span>
            {% endif %}
            {% endnextArchive %}
        </div>
    </div>
    
  4. Code snippet interpretation

    • {% prevArchive prev %}and{% nextArchive next %}These two tags are the starting points for obtaining adjacent article information, and they assign article data separately.prevandnextVariable.
    • {% if prev %}/{% if next %}This is the conditional judgment statement in the template. IfprevornextThe variable has a value (i.e., there is a previous or next article), then executeifThe code inside the block displays the article link; otherwise, if the variable is empty, then execute{% else %}The code inside the block displays the prompt 'Nothing here'.
    • <a href="{{prev.Link}}" title="上一篇:{{prev.Title}}">...</a>This is a standard HTML link tag.{{prev.Link}}and{{prev.Title}}Is the variable output method in AnQiCMS template syntax, which will automatically replace it with the URL and title of the previous article.nextThe link and title of the article are also passed through.{{next.Link}}and{{next.Title}}to output.
    • &laquo;and&raquo;These are HTML entity encodings used to display left and right arrows, enhancing the visual guidance of navigation.
    • You can add more article information to the link as needed, for example{{prev.Thumb}}to display the article thumbnail and further enrich the navigation visual effects.
  5. **Style optimization

Related articles

How does the content list on the search results page dynamically display based on the user's query keywords?

In website operation, the search function is the core to enhance user experience and help users quickly find the information they need.A highly efficient and intelligent search results page can not only meet the immediate needs of users, but also effectively guide traffic and enhance the exposure of website content.AnQiCMS (AnQiCMS) provides us with powerful tools that allow the content display on the search results page to be flexibly and dynamically adjusted according to the user's query keywords, thereby achieving more accurate and personalized content presentation.### Core Mechanism: Understanding AnQiCMS

2025-11-09

How to create custom fields in the document model and flexibly call them for display in the front-end template?

AnQiCMS (AnQiCMS) has provided great convenience for us to build personalized websites with its flexible content model.We all know that the content structure of each website is different, and the traditional "article", "product" model often fails to meet all the details display needs.At this time, custom fields have become an indispensable tool for website operation and content management.This article will guide you step by step on how to create custom fields in Anqi CMS and flexibly display their content on the website front-end template.### The First Part

2025-11-09

How to display AnQiCMS system configuration information on the front end (such as website name, Logo, filing number)?

In AnQi CMS, when building a website, the first thing to consider is often how to elegantly display basic system configuration information on the website front-end, such as the website name, Logo image, and ICP record number.This information is not only the 'front door' of the website, it concerns the brand image, but also an important part of enhancing user trust and even complying with laws and regulations.AnQi CMS provides us with a very convenient way, easily realizing the dynamic call of these system information through template tags.###

2025-11-09

How does the template inheritance feature help developers build a unified and easy-to-maintain page layout?

In AnQiCMS, building a unified and easy-to-maintain page layout is crucial for the long-term healthy operation of any website.As the face of a website, the visual consistency of a page directly affects user experience and brand image;The maintenance efficiency behind it determines the speed of content updates and feature iterations.AnQiCMS's powerful template inheritance feature is the core tool to solve this challenge.The core concept of template inheritance lies in **reusability and layering**.It allows us to create a basic "master" template that includes the common structure and elements of all web pages, such as headers and footers

2025-11-09

How do related document tags intelligently display content similar to the current article topic?

How to guide visitors to more related content naturally after they finish reading an article in content operation, which can not only significantly improve user experience, but also effectively extend the visitors' stay on the website, reduce the bounce rate, and thus have a positive impact on search engine optimization (SEO).AnQi CMS is well-versed in this, providing intelligent and flexible mechanisms that allow us to easily implement this "You might also like" content recommendation.### Content Tag: The First Step of Building Associations AnQi CMS realizes smart content association through its powerful "tag" feature

2025-11-09

How to correctly display the current page path information in the breadcrumb navigation of a website?

The website is operational, a clear navigation path is crucial for user experience and search engine optimization (SEO).When a visitor enters a deep page of the website, the breadcrumb navigation (Breadcrumb Navigation) is like a trail of breadcrumbs that guides them back, helping them understand their position in the website structure and making it convenient to return to the upper-level page.In AnQiCMS (AnQiCMS), implementing an efficient and practical breadcrumb navigation to correctly display the path information of the current page is simpler than you imagine.

2025-11-09

Does AnQiCMS support displaying the document list under a specific Tag on the front end?

In AnQi CMS, you can of course easily display the document list under a specific Tag (label) on the frontend.This is not only a basic function of a content management system, but AnQi CMS also enables you to achieve this in a very fine and user-friendly manner through its flexible template tag system, thus better organizing content and improving the user experience and SEO performance of the website.Starting from version 2.1.0 of AnQi CMS, the system introduced powerful article and product Tag label features, which means you can now add one or more tags to your content (whether articles or products)

2025-11-09

How to introduce third-party JavaScript libraries (such as Markdown, mathematical formulas, flowcharts) in templates to enhance content display?

In AnQiCMS, introducing third-party JavaScript libraries is a very effective means to make your content display more expressive and professional.For example, writing clear text with Markdown, displaying complex mathematical formulas with MathJax, or using Mermaid to draw intuitive flowcharts can greatly enrich the user's reading experience.The powerful template system of AnQiCMS provides us with a flexible integration method.## AnQiCMS template system overview First

2025-11-09