How to display the link to the previous and next documents on the AnQiCMS document detail page?

Calendar 👁️ 79

In the ocean of website content, users often hope to browse related information smoothly and do not want to return to the list to look for the next one after reading a wonderful article.This not only affects user experience, but also benefits the internal link structure of the website and search engine optimization (SEO) as well.AnQiCMS fully considered this point, providing a convenient and quick navigation function for the content detail page, allowing users to easily jump between different documents.

The AnQiCMS template system is very flexible, it draws on the syntax of the Django template engine, making it easy for developers and operators to get started.We all离不开the use of template tags in the display of our pages.To implement the 'Previous' and 'Next' links on the document detail page, we will mainly useprevArchiveandnextArchiveThese tags are specifically designed for document navigation.

When a user visits the details page of a document, these tags can intelligently identify the position of the current document in its category and automatically find the information of the previous and next documents, including their titles and links.So, we can directly generate clickable navigation links at the appropriate position on the page, such as at the bottom of the article, to guide users to continue reading.

How to add previous and next page links on the document detail page?

To implement this feature, we first need to find the template file responsible for rendering document details. Usually, this will be located according to your website's configuration./template/您的模板目录/{模型table}/detail.htmlIn the file. For example, if it is an article model, it might be/template/default/article/detail.html.

Open thisdetail.htmlAfter the file, you can insert it below the document content, or at any location you think is appropriateprevArchiveandnextArchive.

The use of these tags is very intuitive. You just need to place them in the template like this:

<nav 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>
</nav>

Let's explain this code in detail:

  1. {% prevArchive prev %}and{% nextArchive next %}: This is the two core tags provided by AnQiCMS.They will try to get the data of the previous and next documents of the current document.We will assign the data we obtain toprevandnextThese two variables.

  2. {% if prev %}and{% if next %}This is a very important judgment. Not all documents have a previous or next one, for example, the first document does not have a previous one, and the last document does not have a next one.We use to avoid displaying empty links or unnecessary informationifTags to checkprevornextDoes the variable exist. If it exists, display the corresponding link;If it does not exist, we can display prompts such as 'No previous article' or 'No next article' to enhance the user experience.

  3. {{ prev.Link }}and{{ prev.Title }}: WhenprevornextWhen a variable exists, we can access.their properties using syntax, such asLink(the document's URL) andTitle(the document's title). These properties will be used directly to build<a>label'shrefand text content.

By using such simple lines of code, your AnQiCMS website now has a professional and user-friendly article navigation feature.It not only makes the user experience more smooth when browsing the content but also helps search engines better crawl and understand the structure of your website's content, having a positive impact on SEO.You can customize the style of your website according to your needs,navanddivAdd the corresponding CSS styles to make the 'Previous' and 'Next' links more beautiful and prominent on the page.


Frequently Asked Questions (FAQ)

1. Why does the 'Previous' or 'Next' link sometimes show 'No previous article'?

This usually means that the document you are currently viewing is the first or last document in the category.For example, if a document is the first article published on your website, then it naturally has no 'previous document' to jump to.AnQiCMS template of{% if prev %}or{% if next %}Judgment will catch this situation and display the preset prompt information to ensure that the page does not show errors or blank links, providing a better user experience.

2. Can I customize the display text of the 'Previous' and 'Next' links? For example, show 'Previous Article' instead of 'Previous'?

Of course you can. In the above code example, you can see that we write text directly inside the<a>tags, for example« 上一篇:{{ prev.Title }}. You can freely modify the text content according to your own taste and the language style of the website, such as changing it to« 上一篇文章:{{ prev.Title }}OrPrevious Post: {{ prev.Title }}, just adjust the text in the template file.

3. What is the sorting logic of these links? What criteria are used to determine which article is the 'previous article' or 'next article'?

prevArchiveandnextArchiveThe tag is usually determined by the document's publication time (CreatedTime) and the document ID's order in its category to determine the 'previous' and 'next' documents.As a rule, a larger ID represents a document that was published later. Therefore, 'Previous' refers to the document that was published before the current one (with a smaller ID or earlier release time), while 'Next' refers to the document that was published after the current one (with a larger ID or later release time).This sorting logic ensures that users can browse content in the order of publication.

Related articles

How to retrieve and display the complete content and properties of a single document using the `archiveDetail` tag?

When using AnQiCMS to build website content, displaying the complete information of a single document is one of the core requirements.No matter whether it is the detailed content of an article, a detailed introduction of a product, or any other specific entry of a custom content model, a highly efficient and flexible way is needed to extract and present this data.This is where the `archiveDetail` tag comes into play.

2025-11-07

How to add pagination and optimize the display effect for document lists in AnQiCMS?

In website operation, how to efficiently display a large amount of content while ensuring the smoothness of user experience is a topic that cannot be ignored.The pagination feature of the document list is the key to solving this problem.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides intuitive and powerful template tags, allowing you to easily add pagination features to document lists and optimize the display on top of that, making your website content more attractive.

2025-11-07

How to filter and display the document list of a specified category or model with the `archiveList` tag in AnQiCMS?

AnQiCMS as an efficient enterprise-level content management system, provides users with flexible and diverse content management and display capabilities.When building a website, we often need to display document lists based on specific conditions, such as only showing articles in a particular category, or only listing entries of specific content models (such as products, services).At this time, the `archiveList` tag has become a powerful tool in our hands.It is not only powerful but also very intuitive to use, making it easy for us to meet these needs.### `archiveList`

2025-11-07

How to use the `for` loop tag in AnQiCMS template to iterate and display content list?

In AnQiCMS, efficiently displaying content lists is a core requirement for website operation.Whether it is articles, products, categories, or custom data, we need a flexible mechanism to traverse and present this information.AnQiCMS's powerful template engine provides a `for` loop tag, which acts as a helpful assistant, making it easy for us to achieve this goal.

2025-11-07

How does the `relatedArchive` tag display a list of related articles based on document relevance?

In the daily operation of a website, how to make users naturally discover more interesting content after reading an article is the key to improving user experience, extending the time spent on the website, and even optimizing SEO effects.AnQi CMS understands this and provides powerful template tag features, where the `relatedArchive` tag is exactly used to intelligently display related article lists.## `relatedArchive` label

2025-11-07

How does the AnQiCMS `categoryList` tag display hierarchical category structures and show category information?

In AnQi CMS, website categories are the foundation for organizing content. Whether it's articles, products, or other custom models, a clear category structure can greatly enhance user experience and the website's SEO effectiveness.The Anqi CMS provides a powerful `categoryList` tag, allowing us to flexibly display single or multi-level classification structures and easily obtain detailed information about each classification.### Master the basic usage of the `categoryList` tag To display the category list, we first need to use the `categoryList` tag

2025-11-07

How to retrieve and display detailed information such as description, Logo, etc. for a specific category using the `categoryDetail` tag?

In AnQiCMS template development, obtaining and displaying detailed category information is a key step in building rich and user-friendly pages.The `categoryDetail` tag was created for this purpose, it can help you easily retrieve the description, Logo, custom fields, and other detailed content of a specific category at any location on the page.### `categoryDetail` tag's core function The main function of the `categoryDetail` tag is to obtain detailed data of a single category

2025-11-07

How does the `pageList` tag display all the titles and links of the individual pages of the website?

In Anqi CMS, using the `pageList` tag to display the titles and links of all single pages is a very common and practical need in website layout and navigation settings.Whether it is used for website footer navigation, sidebar link list, or building a simple HTML site map, the `pageList` tag can help us efficiently achieve these functions. ### Understanding AnQi CMS Single Page Firstly, let's briefly review the "single page" in AnQi CMS.In the Anqi CMS backend management, there is a special "Page Resources" module

2025-11-07