How to display the 'Previous' and 'Next' documents of the current document on the front page to enhance the user's browsing experience?

Calendar 👁️ 62

In AnQiCMS (AnQiCMS), adding 'Previous' and 'Next' navigation links to the front-page document is an important means to enhance user browsing experience and prolong user stay time.When a user finishes reading a piece of content, these links can guide them naturally to discover more related content, avoid interruptions in page browsing, effectively reduce the bounce rate, and help enhance the overall weight of the website's content.

AnQi CMS is a feature-rich Go language content management system with a powerful template tag system, allowing website operators to flexibly control content display.Among them, the "Previous" and "Next" document tags are designed to achieve seamless content navigation.They can intelligently identify and display links to adjacent documents based on the current document's order in the category.

Core function: easily implement with built-in tags

The Anqi CMS template system providesprevArchiveand the previous document"),nextArchive(Next document) These two special tags. Their use is very intuitive, requiring no complex programming knowledge, just a simple configuration in the template file on the document detail page.They automatically retrieve information about the previous or next document in the same category of the current document and generate the corresponding link.

Implementation steps: Add 'Previous' and 'Next' links on the front page

To display the "Previous" and "Next" links on the front page, you usually need to modify the document detail page template. In Anqi CMS, the document detail page template file is usually located in the template directory under your directory.{模型table}/detail.htmlFor example, the detail page of the article model might bearticle/detail.html)

Here are the specific steps and code examples for adding these links:

1. Find the template file for your document detail page

First, you need to log in to the Anqi CMS backend, go to the 'Template Design' module, and find the template currently used on your website.Then, locate the document detail page template you want to modify in the template file list.usually it may be calleddetail.htmlOr name according to your content model, such asarticle/detail.htmlorproduct/detail.html.

2. Insert navigation code in the template file

In the found template file, select a suitable position to place the 'Previous' and 'Next' links, such as below the document content or above the footer. We will useprevArchiveandnextArchiveThese tags are used to retrieve information about adjacent documents.

Please note that these tags will try to retrieve the previous or next document, but if the current document is already the first or last in the category, then the corresponding 'previous' or 'next' will not exist. Therefore, we need to combineifJudge the tag to elegantly handle this situation, ensuring that the page does not appear with blank links or errors when there are no adjacent documents.

Here is a standard implementation example:

<div class="document-pagination">
    <div class="prev-document">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="« {{ prev.Title }}">« 上一篇:{{ prev.Title }}</a>
            {% else %}
                <span>« 没有上一篇了</span>
            {% endif %}
        {% endprevArchive %}
    </div>
    <div class="next-document">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }} »">下一篇:{{ next.Title }} »</a>
            {% else %}
                <span>没有下一篇了 »</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

3. Code Explanation

  • <div class="document-pagination">: This is a wrapping element used for the overall layout and style control of the previous/next link.You can replace it with other HTML tags or classes according to your design.
  • {% prevArchive prev %} ... {% endprevArchive %}: This is a label block to obtain the information of the previous document. It will try to find the previous document of the current document and assign its information to a temporary variable namedprev.
  • {% if prev %} ... {% else %} ... {% endif %}This is a conditional judgment.
    • IfprevThe variable exists (i.e., there is a previous document), then execute.ifThe code within the block displays the link to the previous document.
    • IfprevThe variable does not exist (i.e., this document is the first one), then executeelseThe code within displays a prompt indicating “No previous post”.
  • <a href="{{ prev.Link }}" title="« {{ prev.Title }}">« 上一篇:{{ prev.Title }}</a>: This is the actual link to the previous document.
    • {{ prev.Link }}: It will be replaced with the URL address of the previous document.
    • {{ prev.Title }}This will be replaced by the title of the previous document.
    • title="..."AddtitleProperties can enhance user experience (displaying the title when hovering over the mouse) and SEO.
  • {% nextArchive next %} ... {% endnextArchive %}This is related toprevArchiveThe tag is similar, used to obtain the information of the next document and assign it to a temporary variable namednextThe internal logic is also the same as that of the previous document.

4. Save the template and view the effect

After you finish modifying the code, save your template file and refresh the front-end page to see the effect. You will find that there are 'Previous' and 'Next' navigation links at the bottom of the document.

Optimization and personalization

  • Add Style (CSS): The above code only provides the basic HTML structure. To make these links look more attractive, you need to add.document-pagination,.prev-document,.next-documentAdd the corresponding CSS styles to the class. For example, you can set them to float left and right, adjust the font size and color, or add borders and background colors.
  • Display thumbnailsIf you want the link to be more attractive, you can display a thumbnail of the previous/next document next to it.prevandnextVariables also support thisThumbfield, used to get the document thumbnail address.
    
    {% if prev %}
        <a href="{{ prev.Link }}" title="« {{ prev.Title }}">
            {% if prev.Thumb %}<img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="doc-thumb">{% endif %}
            « 上一篇:{{ prev.Title }}
        </a>
    {% endif %}
    
  • Custom no document promptWhen there is no previous or next document,<span>« 没有上一篇了</span>This prompt can be customized according to your website style.For example, you can change it to "go back to the article list" and link to the category homepage, or simply do not display any content to keep the page simple.

By following these simple steps and flexible customization, you can provide users with a smooth and efficient content browsing experience on the front page of the website built with Anqi CMS, making visitors stay longer on your website and discover more valuable information.


Frequently Asked Questions (FAQ)

Q1: Why did I add the 'Previous'/'Next' code on the document detail page, but no links were displayed on the front page?

A1:

Related articles

How to accurately display the detailed content of a specific AnqiCMS document on the front page, including the title, description, and image?

AnQiCMS (AnQiCMS) leverages its flexible content model and intuitive template tag system, allowing you to easily manage the display of website front-end content.It is particularly important to understand the core mechanism and common tags when we need to present the detailed content of a specific document accurately on the front page, such as the title, description, full text, and related images.### Understanding the content structure of Anqi CMS In Anqi CMS, all content is organized based on the "content model", such as common article models, product models, etc.

2025-11-09

How to use AnqiCMS document list tags to display the latest, hot, or specified category of articles/products on the front page?

In AnqiCMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether you want to highlight the latest articles on the homepage, display popular products in the sidebar, or customize content lists for specific columns, AnqiCMS's powerful document list tags can help you a lot.By skillfully using these tags, you can easily achieve a diverse presentation of content, making your website more dynamic and attractive.### Core Tag: `archiveList`

2025-11-09

How to call and display the detailed content and images of a specific page in AnqiCMS on the front page?

In AnQiCMS, it is actually much simpler than you imagine to call and display the detailed content and images of a specific single page on the front page.AnQiCMS's powerful template tag system, especially the tags designed for single-page layouts, can help you achieve this easily. ### Understanding AnQiCMS Single Page Functionality Firstly, we know that AnQiCMS provides an independent "Page Management" module that allows us to create independent single pages such as "About Us", "Contact Information", or "Service Introduction".This page's content, images, SEO information, etc.

2025-11-09

How to use AnqiCMS's single page list tag to flexibly display independent pages such as 'About Us' on the front end?

In modern website operations, pages like "About Us", "Contact Information", and "Terms of Service" are independent pages that carry the basic information and brand image of the website. Although they are not updated often, they are crucial.AnqiCMS provides a flexible single-page management feature, combining its powerful template tag system, we can easily display these independent pages on the front end and customize them as needed.

2025-11-09

How to display the AnqiCMS related document list on the front page to increase content relevance and user stay time?

In content operation, we all hope that users can stay longer on the website and browse more content.An精心 crafted article is indeed important, but how to connect it with other relevant content to form a content matrix is the key to improving user experience and reducing bounce rate.Imagine, after a user finishes reading an article about 'AnQi CMS Core Features', if the page below automatically recommends 'How to Build an E-commerce Site with AnQi CMS' or 'AnQi CMS Template Creation Tutorial', wouldn't it be more attractive for them to continue exploring?

2025-11-09

How to display the custom parameter fields of AnqiCMS documents on the front page, such as authors, sources, and so on?

In website operation, the flexibility of the Content Management System (CMS) is crucial.AnQi CMS, with its powerful customizability, allows us to add various custom parameter fields to content (such as articles, products, etc.) to meet diverse display needs.These custom fields, such as the 'author', 'source', 'model', 'color' of products, etc., can greatly enrich the dimensions and practicality of content.How can we elegantly present these personalized custom parameters to visitors on the website frontend after we have added them in the background of the document

2025-11-09

How to implement the AnqiCMS document parameter filtering function on the front page to help users quickly locate content?

How to help users quickly find the information they are interested in on increasingly rich content websites is a crucial operational challenge.Users often need to filter content based on specific conditions rather than browsing aimlessly.AnqiCMS provides a powerful document parameter filtering function that allows you to easily achieve this goal on the front page, greatly enhancing user experience and content discoverability.

2025-11-09

How to display the AnqiCMS document Tag list on the front page and support filtering by letter or category?

In a content management system, a tag (Tag) is a powerful tool that helps us organize content more flexibly and improve the efficiency of users in finding relevant information.AnQiCMS as an efficient enterprise-level content management system naturally also deeply integrates powerful tag features.If you are hoping to display a list of document tags on the website front end and allow users to filter by letter or category, this article will provide you with a comprehensive guide.

2025-11-09