How to display the titles and links of the previous and next documents on the document detail page?

Calendar 👁️ 77

In website content operation, providing a smooth reading experience for readers is crucial.When a user finishes reading a document, if they can easily jump to the previous or next related content, it can not only effectively extend the user's stay on the website and increase the page views, but also help search engines better understand the structure and content relevance of the website, thereby having a positive impact on SEO.AnQiCMS (AnQiCMS) has fully considered this point in the design of the template function, providing simple and powerful tags to make it easy to display the title and link of the previous and next document in the document detail page.

To implement this feature, we need to modify the template file of the corresponding document detail page. In AnQi CMS, the template for the document detail page is usually located in your template folder, the path is similar to{模型table}/detail.htmlFor example, if it is an article model, you may need to editarticle/detail.htmlorarchive/detail.html(Determined by your model name).

Anqi CMS provides two very practical template tags for this:prevArchiveandnextArchiveThese tags can intelligently identify the current document and automatically search and provide information about adjacent documents.

How to useprevArchiveShow the previous document

prevArchiveThe tag is used to get the previous document data of the current document. You can use it in your document detail template like this:

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

In this code block:

  • {% prevArchive prev %}A variable was declaredprevto store the information of the previous document.
  • {% if prev %}It is a conditional judgment to check if there is a previous document. If there is, it will render a link; otherwise, it will display 'There is no previous one.'.
  • {{ prev.Link }}It will output the link address of the previous document.
  • {{ prev.Title }}It will output the title of the previous document.

In this way, you can easily create a navigation link to the previous document on the page.

How to usenextArchiveDisplay the next document

withprevArchivesimilar,nextArchiveThe tag is used to get the next document data of the current document. Its usage is also very intuitive:

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

The logic of this code is related toprevArchiveThe same, but it retrieves the information of the next document and stores it in a variablenext.

Integrated into the document detail page practice

Generally, we would place the navigation links to the previous and next articles at the bottom of the document content, or in the sidebar, to facilitate user browsing. A common layout might be:

<article>
    <!-- 这里是文档的标题、内容等核心部分 -->
    <h1>{{ archive.Title }}</h1>
    <div class="content">
        {{ archive.Content|safe }}
    </div>

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

This code provides a basic structure, you can beautify these navigation links according to your website design, for example, add arrow icons, display thumbnails, etc., to improve user experience.prevandnextVariables are used toLinkandTitleIn addition, it also supportsThumb(thumbnail),Description(Description) and other fields, allowing you to create more colorful navigation styles.

By using the above method, you can effectively utilize the Anqi CMS template tags to add practical navigation functions to the document detail pages of your website, allowing users to freely navigate on your site.


Frequently Asked Questions (FAQ)

  1. Why do I not see the links to the previous or next document on the page after I added tags?This usually has several reasons. First, make sure you are modifying the correct document detail page template file (such asarchive/detail.htmlorarticle/detail.htmlCheck if there are adjacent documents on your website.If there is no previous or next document (for example, the current document is the first or last in a category), the corresponding link will naturally not be displayed.Also, make sure the template code does not have any spelling errors, especiallyprevArchiveandnextArchivetags and their variable names.}

  2. How does AnQi CMS determine which document is the 'previous' or 'next' document?The AnQi CMS defaults to finding the previous and next documents in terms of time or ID in the category (Category) of the current document, based on the current document's publishing time (CreatedTime) or document ID.This means that only documents in the same category will be considered as adjacent documents for navigation.

  3. Can I display other information about the 'previous' or 'next' document in addition to the title and link?Of course you can.prevandnextA variable is a complete document object, excludingTitle(Title) andLink(links) they also contain many other available fields, such asId(Document ID),Thumb(thumbnail),Description(Summary),Views(Views) andCreatedTime(publish time). You can meet your needs, within{% if prev %}or{% if next %}the block through{{ prev.Thumb }}/{{ next.Description }}In a way that calls this information to create more attractive navigation between the front and back documents.

Related articles

How to display a list of recommended documents related to the current document on the document detail page?

In website content operations, providing users with relevant recommended content not only effectively enhances the depth and duration of page browsing, but also optimizes user experience, indirectly assisting in the SEO performance.In AnQiCMS (AnQi Content Management System), implementing this feature is flexible and direct.Next, we will discuss how to seamlessly integrate and display the recommended document list closely related to the current document on the document detail page. ### Core Value: Why should recommended documents be displayed on the document detail page?

2025-11-08

How to get and display the name and link of the category to which the current document belongs?

On the content detail page of a website, we often hope to clearly display the classification information of the current document, such as the name of the classification and the link to that classification.This not only helps visitors better understand the content structure, but also improves the website's navigation and user experience.Safe CMS provides us with a variety of flexible ways to meet this requirement. We will discuss several methods for obtaining and displaying the category name and link of the current document in the AnQiCMS template, and you can choose the most suitable solution according to your actual template design and requirements.### Method One

2025-11-08

How to implement lazy loading of images in document content to optimize display performance?

## Optimize Website Display Performance: Practical Guide to Implementing Lazy Loading of Images in AnQi CMS In today's internet era, the loading speed of a website is crucial for user experience and search engine rankings.Large image files are often one of the main culprits slowing down website loading speeds. 幸运的是,image lazy loading (Lazy Loading) technology can effectively solve this problem.

2025-11-08

How to call and display the cover image, thumbnail, or group image of a specified document?

It is crucial to have visually appealing content when building and operating a website.AnQiCMS provides a flexible way to manage and display the images of documents (including articles, products, etc.), whether as an eye-catching cover, a clever thumbnail, or a colorful group photo.Understand how to correctly call these images, which can help you better design and optimize the user experience of the website.AnQiCMS provides several main image fields for different content types, which have clear uses in the template: * **Cover logo (Logo)**

2025-11-08

How to call and display the data of the custom model field in the document?

In Anqi CMS, the flexible content model is one of its core strengths, allowing us to create various information carriers such as articles, products, and more according to different business needs and define unique properties for them.How to present the data of these customized fields in the website front-end after we have set them for the document is a major concern for many users.This article will provide a detailed explanation of this process, helping you easily master the custom model fields of Anqi CMS. ### Understanding the Value of Custom Model Fields Firstly, let's clarify the importance of custom model fields.

2025-11-08

How to filter and display a document list based on specific recommendation attributes (such as 'Headline', 'Recommendation')?

The flexible application of content recommendation properties in AnQiCMS is a key link in enhancing the visibility and user experience of website content.Whether you want to highlight important news on the homepage or recommend selected content in specific sections, AnQiCMS provides a convenient and efficient solution.This article will delve into how to filter and display document lists based on specific attributes such as 'Headlines' and 'Recommendations', helping you better manage and present website content.### Part One: Understanding Recommendation Properties and Their Settings Recommendation properties are a very practical feature in the AnQiCMS content management system

2025-11-08

How to implement keyword search and display results on the document list page?

How to help visitors quickly and accurately find the information they need in the face of increasingly large amounts of website content is the key to improving user experience and website value.AnQiCMS (AnQiCMS) is deeply proficient in content management, providing us with a powerful and flexible keyword search mechanism that allows the document list page to easily implement keyword search and elegantly present the results.

2025-11-08

How to implement multi-condition (such as custom parameters) filtering function on the document list page?

In AnQi CMS, implementing multi-condition filtering functionality on the document list page, especially filtering based on custom parameters, is crucial for improving user experience and helping users quickly find the content they need.AnQi CMS with its flexible content model and powerful template tag system makes this feature highly efficient and intuitive.The entire process can be divided into several core steps: First, define your content model and custom filter fields in the background;Secondly, build the display interface for the filtering conditions in the template; finally, present the filtering results in the document list using list tags.--- ### One

2025-11-08