How to correctly display the link and title of the previous/next document in AnQiCMS template?

Calendar 78

How to elegantly display the link and title of the previous/next document in the AnQiCMS template?

Users often want to easily jump to related content while browsing articles on a website, whether it's going back to the previous one for a deeper understanding or continuing to read the next new content.This "previous/next article" navigation feature can not only significantly improve user experience and extend the time users stay on the website, but also has great benefits for the internal link structure and SEO optimization of the website.AnQiCMS with its powerful template engine similar to Django makes it very intuitive and flexible to meet this requirement.

Next, we will explore how to correctly and efficiently display the link and title of the previous/next document in your AnQiCMS template.

Core Tag Introduction:prevArchiveandnextArchive

AnQiCMS provides two very intuitive and powerful template tags specifically designed to retrieve the previous and next documents of the current document:prevArchiveandnextArchive.

These tags are block-level tags, which means they need an opening tag ({% prevArchive ... %}) and a closing tag ({% endprevArchive %}Enclose the content within tags. Inside the tag, you can assign the obtained document data to a variable (for exampleprevornext), then access the various properties of the document through this variable, such as title, link, thumbnail, etc.

When you use these two tags on the document detail page, they will automatically find the previous or next document based on the current document context (usually documents in the same category). They support retrieving various fields of the document, including:

  • Id: Document ID
  • Title: Document Title
  • Link: Document Link
  • Description: Document Summary
  • Thumb: Document thumbnail
  • And other inarchiveDetailFields available in the tag.

Actual Operation: Step by step implementation of previous/next article navigation

Let us understand how to add navigation for previous/next document in AnQiCMS template through actual code examples.

Step 1: Determine the template file.

Firstly, we need to find the template file used by the current document detail page. According to the template convention of AnQiCMS, the document detail page is usually located at/template/您的模板目录/{模型table}/detail.htmlor{模型table}/detail-{文档ID}.htmlFor example, if it is an article model, you may need to modifyarticle/detail.htmlin the process.

Step two: Insert basic code (link and title)

Find the area near the document content display where you want to show the previous/next navigation. Usually, they are placed at the bottom of the article content.

While usingprevArchiveandnextArchiveWhen labeling, there is a very important point to note:Not every article has a previous or next one.For example, the first article in a category does not have a previous one, and the last article does not have a next one.Therefore, when using these tags, we must add conditional judgments to avoid displaying empty links or unnecessary placeholders, thereby improving user experience and page cleanliness.

The following is a basic code example that determines if there is a previous or next article and displays the corresponding link and title, or displays a prompt if there is none:

<nav class="document-pagination">
    <div class="prev-document">
        {# 上一篇文档 #}
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                    <span class="arrow">&laquo;</span> 上一篇: <span class="title">{{ prev.Title }}</span>
                </a>
            {% else %}
                <span class="no-entry">&laquo; 没有上一篇了</span>
            {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-document">
        {# 下一篇文档 #}
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }}">
                    下一篇: <span class="title">{{ next.Title }}</span> <span class="arrow">&raquo;</span>
                </a>
            {% else %}
                <span class="no-entry">没有下一篇了 &raquo;</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</nav>

In this code block:

  • We use{% prevArchive prev %}and{% nextArchive next %}Retrieve the data of the previous and next documents and assign them toprevandnextVariable.
  • {% if prev %}and{% if next %}Conditionally ensure that the link is rendered only when the corresponding document exists.
  • {{ prev.Link }}and{{ prev.Title }}Used to obtain the link and title of the document.nextThe usage of variables is similar.
  • If it does not exist, we will display a friendly prompt message.

Step 3: Add more details to enhance user experience (with thumbnails and descriptions)

It may seem monotonous to have just text links, we can consider adding document thumbnails or summaries to enrich the display, so that users can have a more intuitive understanding of the content before jumping to it.

AnQiCMS'prevArchiveandnextArchiveTags also support retrievalThumb(Thumbnail) andDescription(Summary) field, making our navigation more attractive.

`twig

Related articles

How to enable WebP image format in AnQiCMS to improve image loading speed and display efficiency?

Enable WebP image format in AnQiCMS: Optimize loading speed and display efficiency In today's digital age, website loading speed is one of the key factors in user experience and search engine ranking.Images are an important part of a website's content, and their loading efficiency has a crucial impact on the overall performance of the page.If the image size is too large or the format efficiency is low, it will not only slow down the website loading speed, but also consume the valuable traffic of users, and even affect the performance of the website in search engines.

2025-11-07

How does AnQiCMS ensure that the front-end displayed content is UTF-8 encoded and avoids garbled characters?

In website operation, content encoding is a crucial link, which directly affects whether users can read the text on the page normally.If encoding is not unified, the appearance of乱码 not only will seriously affect the user experience, but may also lead to information transmission errors.For AnQiCMS, ensuring that the content displayed on the front end is UTF-8 encoded to avoid garbled text issues is a core consideration in its system design and content management.First, Anqi CMS has provided a solid foundation for UTF-8 encoding in its underlying technical architecture.

2025-11-07

How to use filters (such as `truncatechars`) in AnQiCMS templates to truncate long text content and display it friendly?

In website operation, how to efficiently display content while ensuring the page is neat and beautiful is a challenge that every operator needs to face.Especially when the title, introduction, or comments of an article are too long, if they are not processed, it is easy to break the page layout and affect the user experience.Luckyly, AnQiCMS provides a powerful and flexible template filter function, among which the `truncatechars` filter and other truncation filters can help us solve this problem elegantly.Optimize Content Display: Why Do We Need to Truncate Text?

2025-11-07

How to replace specific characters in a string in AnQiCMS, affecting the presentation of front-end content?

In website operation, we often encounter situations where we need to modify or adjust the content, which is not just about updating text.Sometimes, we need to replace a specific word on a website with a new expression, or update links in bulk, or even dynamically process certain characters during content presentation.AnQiCMS as an efficient content management system provides a variety of flexible mechanisms to handle string replacement, thereby finely controlling the presentation of front-end content.### Backend bulk replacement: The efficiency tool for global content updates Imagine that the website you operate uses a specific product name

2025-11-07

How to display user details such as avatar and username in AnQiCMS templates?

In AnQiCMS, flexibly displaying users' detailed information in templates, such as avatars and usernames, is an important step to achieve personalization and enhance website interaction.AnQiCMS's powerful template engine provides an intuitive and efficient way to integrate these data. ### Understanding the Data Calling Mechanism of AnQiCMS Template AnQiCMS template system uses a syntax style similar to Django, which makes template writing both intuitive and powerful.The essence lies in using specific template tags to call back-end data.

2025-11-07

How to set the website logo and filing number of AnQiCMS so that it can be displayed correctly on the front-end page?

During the process of building a website, the brand identity (Logo) and the necessary compliance information (record number) are indispensable elements.They can not only enhance the professionalism and credibility of the website, but also provide clear guidance to users.AnQiCMS is an efficient content management system that provides an intuitive and convenient way to set these information and ensures that they are displayed correctly on the website front-end page. Next, we will learn how to set the website logo and filing number in AnQiCMS in detail.

2025-11-07

How to automatically convert URLs to clickable links in AnQiCMS templates using the `urlize` filter?

In website content management, we often need to display external links in articles, comments, or introductions.Manually adding the `<a>` tag to each URL is not only cumbersome but also prone to errors, especially when dealing with large amounts of user-generated content or importing data from other sources.Fortunately, AnQiCMS provides a very practical template filter——`urlize`, which can automatically identify URLs and email addresses in text and convert them into clickable links, greatly simplifying the work of content managers.

2025-11-07

How to configure Docker reverse proxy to display multiple independent websites for AnQiCMS multi-site feature?

AnQiCMS (AnQiCMS) is favored by many website operators for its efficient and flexible content management capabilities.Especially its powerful multi-site management feature, combined with Docker containerization technology and reverse proxy, allows you to easily set up and manage multiple independent websites on the same server, greatly enhancing operational efficiency and reducing maintenance costs. ### Discover the charm of multiple sites Imagine that you may have several different brands, aimed at different audiences, or serving different regions, but their content update and management processes are roughly the same.

2025-11-07