How to get and display the previous/next content of the current document?

Calendar 👁️ 90

In content websites, providing visitors with a convenient navigation experience is crucial, among which the "Previous" and "Next" features are标配of the article detail page.They not only guide users to continue browsing more content, effectively increase the website's PV (page views), but also help search engines better understand the content structure of the website to optimize SEO performance.AnQiCMS fully considered this requirement, providing us with very simple and intuitive template tags to easily achieve this function.

Learn about the template mechanism of AnQiCMS

In AnQiCMS, we control the display of website pages by writing template files. The templates use syntax similar to Django, through double curly braces{{ 变量名 }}Output variable content, through{% 标签 %}Use feature tags or perform logical control. Implement navigation to the previous and next articles, mainly relying on the system built-in.prevArchiveandnextArchive.

These tags are usually on the article or product detail page (such asarchive/detail.htmlorproduct/detail.htmlThe specific filename may vary depending on the custom template used, as they need to find adjacent content based on the document being viewed.

How to retrieve and display the previous document?

AnQiCMS provides a special tagprevArchiveGet the previous content of the current document. When we use this label on the document details page, it will automatically identify the current document and find the previous document in the same category.

The followingprevArchiveBasic usage of the tag:

{% prevArchive prev %}
    <div class="prev-article-link">
        {% if prev %} {# 判断是否存在上一篇文档 #}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                <span class="label">上一篇:</span>
                <span class="title">{{ prev.Title }}</span>
            </a>
        {% else %}
            <span class="label">上一篇:</span>
            <span class="title">没有了</span>
        {% endif %}
    </div>
{% endprevArchive %}

In the code above:

  • {% prevArchive prev %}The tag will try to get the previous document and assign its data to a namedprev.
  • {% if prev %}Check if the previous document exists. If it does, we can thenprevto access its properties.
  • {{ prev.Link }}It will output the link to the previous document.
  • {{ prev.Title }}It will output the title of the previous document.
  • IfprevThe document does not exist (i.e., it is the first document in the category), it will display

If you want to display a thumbnail of the document next to the link, you can further enrich the code:

{% prevArchive prev %}
    <div class="prev-article-nav">
        {% if prev %}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                {% if prev.Thumb %} {# 判断是否存在缩略图 #}
                    <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="article-thumbnail"/>
                {% endif %}
                <span class="label">上一篇:</span>
                <span class="title">{{ prev.Title }}</span>
            </a>
        {% else %}
            <span class="label">上一篇:</span>
            <span class="title">没有了</span>
        {% endif %}
    </div>
{% endprevArchive %}

Here is an addition{% if prev.Thumb %}Determine, so that the image is displayed only when the thumbnail exists, to avoid displaying placeholders or errors.

How to retrieve and display the next document?

Similar to obtaining the previous document, AnQiCMS providesnextArchivetags to obtain the next document of the current document. Its usage is almost the same, just the direction of retrieval is reversed.prevArchivealmost the same, just the direction of retrieval is reversed.

The followingnextArchiveBasic usage of the tag:

{% nextArchive next %}
    <div class="next-article-link">
        {% if next %} {# 判断是否存在下一篇文档 #}
            <a href="{{ next.Link }}" title="{{ next.Title }}">
                <span class="label">下一篇:</span>
                <span class="title">{{ next.Title }}</span>
            </a>
        {% else %}
            <span class="label">下一篇:</span>
            <span class="title">没有了</span>
        {% endif %}
    </div>
{% endnextArchive %}

Similarly, if you need to display thumbnails:

{% nextArchive next %}
    <div class="next-article-nav">
        {% if next %}
            <a href="{{ next.Link }}" title="{{ next.Title }}">
                {% if next.Thumb %} {# 判断是否存在缩略图 #}
                    <img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="article-thumbnail"/>
                {% endif %}
                <span class="label">下一篇:</span>
                <span class="title">{{ next.Title }}</span>
            </a>
        {% else %}
            <span class="label">下一篇:</span>
            <span class="title">没有了</span>
        {% endif %}
    </div>
{% endnextArchive %}

Integrate display of previous/next navigation

Generally, we will display the navigation for the previous and next articles side by side or stacked at the bottom of the article detail page. Combining the above code snippet can form a complete navigation area.

<div class="article-navigation-container clearfix">
    {# 上一篇文档 #}
    {% prevArchive prev %}
        <div class="prev-article-box">
            {% if prev %}
                <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                    <span class="nav-label">上一篇:</span>
                    <span class="nav-title">{{ prev.Title }}</span>
                </a>
            {% else %}
                <span class="nav-label">上一篇:</span>
                <span class="nav-title">没有了</span>
            {% endif %}
        </div>
    {% endprevArchive %}

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

This has been usedclearfixA style class (assuming your CSS framework includes this feature) to handle float layout, placing the previous and next articles on the left and right sides respectively.You can also adjust the HTML structure and CSS style of your website according to your design.

Useful Tips

  • Code placement location:These code snippets are usually placed in your detail page template file (such as模型名称/detail.html), or if you have used template inheritance, you can place it in the detail page'scontentArea, or a basic template specifically used for the detail page layout.
  • Accessible fields: prevandnextVariables not only provideLinkandTitlebut also allow access to

Related articles

How to display the detailed content of articles or products and support lazy loading of images?

A Guide to Displaying Content Details and Lazy Loading Images in AnQi CMS in Today's Digital World, the way websites present content directly affects user experience and search engine rankings.Whether it is a detailed article introduction or a beautiful product display, how to present the content efficiently and aesthetically to the visitors and ensure the website loading speed is a challenge that every operator needs to face.AnQiCMS (AnQiCMS) is a powerful content management system that provides us with flexible tools to meet these challenges.This article will delve into how to fully utilize the functions of Anqi CMS

2025-11-07

How to display document recommendation attributes (such as headline, recommendation) on the document list or detail page?

It is crucial to highlight the key content on the website in a content management system to attract users and increase page views.AnQiCMS (AnQiCMS) provides powerful document recommendation attribute functions, allowing website operators to flexibly mark and display articles.This article will introduce how to cleverly use these recommended attributes in the document list and detail page of Anqi CMS to make your website content more vivid and guiding.### Learn about the recommended features of AnQi CMS AnQi CMS has designed various recommended features for each document

2025-11-07

How to display a list of articles or products under a specific category in AnQiCMS?

In AnQiCMS, displaying a list of articles or products under a specific category is a common need in website content management.To build subpages under the navigation menu or to showcase selected content from different modules on the homepage, AnQiCMS offers a flexible and powerful way to achieve this goal.Understanding the content organization logic and the use of template tags will allow you to easily present the required content on the website.### Understanding AnQiCMS content model and categories Firstly, the organization of AnQiCMS content is based on "content model" and "categories"

2025-11-07

How to retrieve and display a list of articles or products in a loop?

Build an energetic website in AnQiCMS, the display of the content list is an indispensable part.Whether it is to display the latest released articles, hot products, or content under specific categories, AnQiCMS' powerful template engine can help us easily achieve it.This article will delve into how to retrieve and loop through lists of articles or products in AnQiCMS, helping you flexibly build diverse content display pages.## Understanding AnQiCMS content list mechanism AnQiCMS uses a template engine syntax similar to Django

2025-11-07

How to display the list of recommended content related to the current document in AnQi CMS?

When operating a website, we often hope that users can smoothly find more interesting content after reading a wonderful article.This not only extends the user's stay time and reduces the bounce rate, but is also an effective way to enhance the overall value of the website's content and SEO performance.AnQi CMS knows this, and therefore it provides a variety of flexible ways to display the recommended content list related to the current document, helping us better guide users. To implement recommendations for related content, we first need to understand how Anqicms defines 'related'.In system design, "related" can be reflected at several levels

2025-11-07

How to customize the display of thumbnail and cover images for articles or products?

In website content operation, the visual appeal of images is crucial.Whether it is to show the essence of an article or highlight the highlights of a product, a suitable thumbnail and cover image can greatly enhance the user experience and have a positive impact on the spread of content.AnQiCMS (AnQiCMS) offers rich and flexible features, allowing us to easily customize the display of images for articles or products according to specific needs.This article will introduce how to manage and display thumbnails and cover images in AnQi CMS from two aspects: background configuration and template calling.--- ### One

2025-11-07

How to display the page views and comment count of the document?

In website content operation, accurately displaying the document's page views and user comment numbers is a key indicator of the popularity and user activity of the content.AnQiCMS provides flexible and intuitive template tags, helping us easily display these important data in the various corners of the website without delving into complex backend logic.### Show view count and comment number on document detail page When you want to display the current view count and total number of comments on a single document detail page (such as an article, a product detail page), AnQiCMS's

2025-11-07

How to specify and display different templates for specific documents or categories?

AnQi CMS provides a flexible and powerful template management mechanism that allows users to specify and display unique templates for documents, categories, and even single pages based on different content types or specific needs.This feature greatly enhances the personalized display capabilities and operational efficiency of the website content.Understanding the significance of template customization In website operations, the diversity of content often requires different presentation methods.An in-depth technical article may require a concise and clear layout so that readers can focus on the content itself;A promotional activity page may require prominent visual elements and call-to-action buttons

2025-11-07