How to dynamically fetch and display the previous and next articles of the current article on the article detail page?

Calendar 👁️ 64

How to smoothly transition users to related or next content after they finish reading an article, which is a key factor in improving user experience and website stickiness.Especially for sites with a large amount of content, such as blogs, news websites, or product display websites, a straightforward "previous/next" navigation feature is particularly important.It can not only guide users to deeply browse and reduce the bounce rate, but also provide more internal links for search engines, optimizing the SEO performance of the website.

AnQiCMS (AnQiCMS) is a powerful content management system that fully considers this requirement.It provides a concise and efficient way, allowing you to display the previous and next articles of the current article on the article detail page without writing complex backend code, simply by using template tags.

How to implement the dynamic display of the previous and next articles in AnQi CMS?

AnQi CMS allows you to directly call specific data in the template file of the article detail page. The system is specially designed for displaying theprevArchiveandnextArchiveThese tags. These tags will automatically identify and return the previous and next articles in the order of time in the context of the current article.

Core tag parsing

UnderstandingprevArchiveandnextArchiveThe usage of tags is the key to realizing this function. They all follow a similar calling pattern and provide a series of fields related to articles for display.

1.prevArchiveTag

This tag is used to retrieve information about the previous article of the current article.When there is a previous article, it will return the detailed data of the article;If the current article is the first one, it will not return any content.

  • Basic usage:

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

    here,prevThis is the variable name we define for the data of the previous article, you can name it freely according to your preference.LinkandTitleThis is the link and title field of the previous article, you can access it directly by..operator access.

  • Available article fields:prevArchiveYou can access tags returned objects such asId(Article ID),Title(Article Title),Link(Article Link),Description(Article description),Thumb(Thumbnail) and other commonly used fields.

  • Display example with thumbnail: If your template design needs to display a thumbnail, you can write it like this:

    {% 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 %}
    

2.nextArchiveTag

withprevArchivesimilar,nextArchiveThe tag is used to get information about the "next" article of the current article.If there is a next article, it will return the detailed data of the article;If the current article is the latest one, then no content is returned.

  • Basic usage:

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

    here,nextis the variable name defined for the data of the next article.

  • Available article fields:nextArchiveThe fields available in the object returned by the tag are,prevArchiveTags are consistent, for exampleId,Title,Link,Description,Thumbetc.

  • Display example with thumbnail:

    {% 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 %}
    

Actual operation: Add navigation in the article detail page

Generally, the navigation to the previous and next articles is placed at the bottom of the article content or in a prominent position in the sidebar. In AnQi CMS, you need to edit the corresponding template file for the article detail page (usually{模型table}/detail.htmlPlease refer to the "Template Production Basic Conventions" document).

This is a complete example code block showing how to add 'Previous' and 'Next' navigation at the bottom of the article detail page.

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="上一篇:{{ prev.Title }}">
                    <span class="nav-label">上一篇</span>
                    <span class="nav-title">{{ prev.Title }}</span>
                    {# 如果需要显示缩略图,可以取消注释以下代码 #}
                    {# {% if prev.Thumb %}<img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" />{% endif %} #}
                </a>
            {% else %}
                <span class="no-article">没有上一篇了</span>
            {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-article">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="下一篇:{{ next.Title }}">
                    {# 如果需要显示缩略图,可以取消注释以下代码 #}
                    {# {% if next.Thumb %}<img src="{{ next.Thumb }}" alt="{{ next.Title }}" />{% endif %} #}
                    <span class="nav-title">{{ next.Title }}</span>
                    <span class="nav-label">下一篇</span>
                </a>
            {% else %}
                <span class="no-article">没有下一篇了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

Insert this code into your article detail template file (for examplearticle/detail.html), usually located<article>before the end tag. After that, you can style it according to the overall style of the website using CSS..article-navigation,.prev-article,.next-articleAdd styles to the class to make the navigation look more beautiful and meet the design requirements.

Tips to enhance user experience and SEO

  • Clear navigation text: Use 'Previous: [Article Title]' and 'Next: [Article Title]' descriptions to let users clearly know what content they will be accessing.Avoid using overly simple terms like 'Previous' or 'Next' as they reduce the discoverability of the content.
  • Visual guidance: You can add arrow icons, article thumbnails, and other visual elements to navigation to enhance the attractiveness of clicks.
  • Handle the situation where 'none' is present.: When there is no previous or next article, elegantly display 'None' or hide the navigation item to avoid users clicking on empty links or causing confusion.
  • Internal link optimization: The previous/next navigation naturally creates high-quality internal links, helping search engine spiders discover more pages and pass on page authority.Ensure that the navigation links are clickable and use descriptive anchor text.
  • Increase the stay time: Guide the user to browse more related content, which can effectively extend the user's stay on the website. This is a positive signal for search engines to judge the quality of the website content.

Provided by Anqi CMSprevArchiveandnextArchiveLabel, you can easily add dynamic previous and next navigation to the article detail page of the website, thereby optimizing the user experience and adding bricks and tiles to the website's SEO performance.


Frequently Asked Questions (FAQ)

Q1: If my article has no previous or next article, what will the page display?

A1:In the above template code, we used{% if prev %}and{% if next %}such conditional judgment. If the current article does not have a previous one,prevArchivethe tag does not return data,{% if prev %}The condition will not be met, the page will display that you are in{% else %}Text defined within the block, for example, 'No previous article.' Similarly, if there is no next article, 'No next article' will also be displayed. If you do not want to display any prompts, you can simply omit them.{% else %}the block.

Q2: What determines the order of the previous/next article?

A2: prevArchiveandnextArchiveTags are set by default based on the time of the article's publication (CreatedTimeIn the current category of the article, determine the previous and next articles in chronological order (usually in reverse, that is, the most recently published articles are in front).This means that 'previous article' refers to the next article (or the one that is more recent in sorting) that was published earlier than the current article, while 'next article' is the previous article (or the one that is more recent in sorting) that was published later than the current article.If the article is in a different category, it may not be possible to find the corresponding previous or next article.

Q3: Can I customize the display style of the previous/next article?

A3:Of course you can. By wrapping the HTML element that contains the previous/next link (such as the example shown above).prev-articleand.next-articleAdd CSS styles, you can fully customize their layout, font, color, background, and other visual effects to keep them consistent with the overall design style of your website.The AnQi CMS only provides data, the style is completely controlled by the front-end template and CSS.

Related articles

How to retrieve the custom fields (such as author, source, additional parameters) of the current article and display them?

In Anqi CMS, managing and displaying custom fields for articles such as authors, sources, or additional parameters is a common and practical need in content operation.The Anqi CMS, with its flexible content model design, provides multiple ways to achieve this goal, helping you easily enrich article information and present it to readers in a personalized manner. ### Understanding AnQi CMS Custom Fields Firstly, we need to understand how article custom fields work in AnQi CMS.

2025-11-08

How to obtain and display the title, content, thumbnail, and other core information of an article on the article detail page?

When operating a website, the article detail page is the key entry point for users to understand the core value of the content.A well-designed, comprehensive article detail page that not only improves user experience but also effectively helps search engines understand the content of the page, thus optimizing the website's SEO performance.AnQiCMS (AnQiCMS) provides a powerful and flexible template tag system that allows you to easily obtain and present all the core information of the article.

2025-11-08

How to display the article list according to the article views, publish time, or backend custom sorting?

In website operation, the way articles are displayed directly affects user experience and content access efficiency.A well-organized list of articles that can highlight key points, significantly improving user retention and information acquisition efficiency.AnQiCMS as a flexible content management system provides powerful article list display functions, not only can it flexibly filter content, but also can freely adjust the sorting method of articles according to your content strategy, making your website content more attractive.

2025-11-08

How to filter and display a list of articles based on their recommended attributes (such as “Top Article”, “Recommended”)?

In Anqi CMS, efficient content management is one of the keys to website success.Article recommendation attribute, as an important link in the operation of content refinement, it can help us display website content more flexibly, guide users to pay attention to key information, and thus improve the activity and conversion rate of the website.This article will delve into how to filter and display article lists based on the recommended attributes of articles (such as "Headline

2025-11-08

How does AnQiCMS define and display related articles? Is it based on keywords or manual association?

In website operation, recommending relevant articles is an important strategy to enhance user experience, extend user stay time, and optimize on-site SEO.AnQiCMS provides a flexible and efficient mechanism to define and display related articles, allowing operators to choose between intelligent recommendations or manual association according to their actual needs. ### Smart Recommendation: Dynamic Association Based on Keywords and Tags The smart recommendation mechanism of AnQiCMS mainly relies on the keywords and tags set in the article content. When you edit articles in the background, you can set: * **Document keywords

2025-11-08

How to retrieve and loop through all document lists under a specific Tag (label) in the template?

In AnQi CMS, content organization can not only be achieved through traditional classification methods, but also flexible "Tag" mechanisms provide a wide space for content association and user search.When you want to display all documents under a specific tag in a certain area of the website, such as the sidebar, related recommendation modules, or even a dedicated Tag aggregation page, AnQi CMS provides a powerful and intuitive template tag that makes this process easy.This article will delve into how to use the Anqi CMS template

2025-11-08

How to retrieve and display detailed information of a specified category, including its description, Banner image, and Logo?

In a content management system, categories are not only the form of content organization, but also the core of website structure and user navigation.Flexibly obtain and display detailed information of a specific category, such as its description, unique banner image and logo, which is crucial for creating attractive and informative pages.AnQiCMS (AnQiCMS) provides an intuitive and powerful template tag to meet this need, allowing you to easily achieve this requirement.### Core Function Tag

2025-11-08

How to implement a multi-level nested tree structure display in the category list?

When building website categories, we often need to display a clear, hierarchical structure so that users can intuitively understand the ownership of the website content.AnQiCMS provides powerful template tag features, fully supporting the display of multi-level nested tree structures in category lists, helping you easily create a user-friendly navigation system.The core of achieving this effect lies in the clever use of the `categoryList` template tag of Anqi CMS and its built-in hierarchical judgment function.By looping in the template, you can use the parent-child relationship of the category

2025-11-08