How to display the previous article and

Calendar 👁️ 69

In website content operation, the user experience of the document detail page is crucial.A well-designed page can not only effectively display content but also guide visitors to explore more relevant information.Among these, providing the 'Previous' and 'Next' navigation function for users is a commonly used and efficient strategy to improve the internal link structure of the website, reduce the bounce rate, and optimize the user's browsing path.This not only helps users conveniently explore more content, but also conveys the relevance and depth of the website's content to search engines, which has a positive impact on SEO.

Benefiting from the powerful and flexible template engine of AnQiCMS, achieving this function becomes very direct and efficient.AnQiCMS uses a template syntax similar to Django, allowing easy access to various built-in data and functions with concise tags.For the previous and next navigation on the document detail page, AnQiCMS provides special template tags to allow content developers to quickly integrate.

Skillfully use the "Previous" and "Next" tags of AnQiCMS

AnQiCMS has specially designed the previous and next page features for the document detail page.{% prevArchive %}and{% nextArchive %}These tags. Their purpose is to automatically identify and retrieve the information of the previous and next documents in the same category or based on other logical sorting when the user browses a document.This means, you do not need to manually write complex database queries or logical judgments, AnQiCMS has built these functions into tags, greatly simplifying the development process.

The syntax of these two tags is very intuitive. They both are.{% 标签名 变量名 %}and ends with{% end标签名 %}End. For example, to get the previous document, you can use it like this:{% prevArchive prev %}...{% endprevArchive %}. Here,prevIt is a custom variable name that will carry all related data of the previous document within the tag block. Similarly,{% nextArchive next %}in the labelnextThe variable will contain the data of the next document.

InprevornextIn these two variables, you can access rich document field information, including but not limited to: document ID (Id) document title (Title)Document Link(Link)Document Thumbnail(Thumb)Document Description(Description) etc. These fields are enough to build a fully functional and beautiful navigation area.

Integrate previous/next navigation in the document detail page

To add the navigation for the previous and next articles to your document detail page, you need to find the detail page template file for the corresponding document model. According to the AnQiCMS template conventions, this is usually located{模型table}/detail.htmlFor example, the corresponding article model might bearticle/detail.html)

Before yourdetail.htmlAt the appropriate location in the template file, you can insert the following code snippet to display the previous and next articles:

<nav class="pagination-post">
    <div class="prev-post">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}">
                    <span class="label">上一篇</span>
                    <h4 class="title">{{ prev.Title }}</h4>
                </a>
            {% else %}
                <span class="no-post">没有了</span>
            {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-post">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}">
                    <span class="label">下一篇</span>
                    <h4 class="title">{{ next.Title }}</h4>
                </a>
            {% else %}
                <span class="no-post">没有了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</nav>

In this code, we first use{% prevArchive prev %}and{% nextArchive next %}Tag to try to get adjacent document data. We added one inside each tag block.{% if prev %}or{% if next %}The judgment. This is because not all documents have a previous or next one (for example, the first article in a series does not have a previous one, and the last article does not have a next one).This judgment ensures that only when there are adjacent documents, will the link and title be displayed;Otherwise, it will display a prompt such as

By{{ prev.Link }}and{{ prev.Title }}(or{{ next.Link }}and{{ next.Title }}),We can easily extract the document link and title. You can also further utilize according to your design needs.{{ prev.Thumb }}or{{ next.Thumb }}To display thumbnails, making navigation more eye-catching. For example, if you need to display thumbnails:

<a href="{{ prev.Link }}">
    <span class="label">上一篇</span>
    {% if prev.Thumb %}<img src="{{ prev.Thumb }}" alt="{{ prev.Title }}">{% endif %}
    <h4 class="title">{{ prev.Title }}</h4>
</a>

Please note the code in the abovepagination-post/prev-post/next-post/label/title/no-postThe class names are just examples, you need to combine your own CSS styles to beautify these elements so that they match the overall design style of the website.

By using these convenient tags provided by AnQiCMS, you can add the previous and next navigation to the document detail page very flexibly and efficiently, significantly improving the website user experience and internal link structure, laying a solid foundation for content marketing and SEO.


Frequently Asked Questions (FAQ)

  1. How will the template display if the current document does not have a previous or next one?If the current document does not have a corresponding previous or next document in its category or sorting rules,{% prevArchive %}or{% nextArchive %}within the labelprevornextThe variable will be empty. By adding to the template{% if prev %}or{% if next %}such conditional judgments, you can elegantly handle this situation, for example, displaying 'none' or not displaying the navigation area.

  2. How is the sorting rule for 'Previous/Next'? Can it be customized?The previous/next function of AnQiCMS is usually determined by the document's publication time, ID sequence, or the sorting value set in the background management interface to determine the logical order of the document.This means, they will automatically display the previous and next documents in the same category according to the default order.Currently, these tags do not provide custom sorting parameters directly. However, if you have specific sorting requirements for your document list or archive, you can indirectly affect the logical order of the previous/next article by adjusting the publication time of the document itself or the backend sorting settings.

  3. Besides the title and link, what other information can I display? prevandnextVariables contain rich document information, you can call it freely according to your needs. In addition,Title(Title) andLink(Link) is also commonly used,Thumb(Document thumbnail),Description(Document summary),CreatedTime(Publish time) and so on. You just need to use it in the template.{{ prev.Thumb }}or{{ next.Description }}In this way, you can call these additional information to further enrich the design of your previous/next navigation.

Related articles

How to implement a paginated document list display in `archiveList`?

When managing website content, we often encounter such situations: there are many articles, products, or news under a certain category. If all the content is piled on a single page, it not only causes the page to load slowly and affects user experience, but also makes it difficult for visitors to find what they need in a sea of information.At this point, introducing pagination becomes particularly important. Pagination can break a large amount of content into several small pages, allowing users to browse page by page, greatly enhancing the usability and access efficiency of the website.In AnQiCMS, implementing a document list display with pagination is very intuitive and flexible

2025-11-07

How to use the `archiveList` tag to display a document list according to specified conditions (such as latest, most popular, recommended attributes)?

AnQiCMS is an efficient and flexible content management system that provides a variety of content display methods, among which the presentation of the document list is a very core part of website operation.We hope to dynamically display the latest articles, the most popular content, or carefully recommended high-quality documents on the homepage, category pages, or thematic aggregation pages according to different operational objectives.All of this can be easily achieved through the powerful `archiveList` tag of AnQiCMS

2025-11-07

How to correctly render Markdown content as HTML and display mathematical formulas and flowcharts in the Anqi CMS template?

The content is the soul of the website, and how to present these contents efficiently and beautifully is a topic of concern for every operator.In AnQi CMS, using Markdown to write content not only greatly improves writing efficiency, but also easily achieves complex layout requirements, such as inserting mathematical formulas and drawing flowcharts. This is undoubtedly a powerful feature for technical blogs, educational websites, or corporate websites that need to display complex business processes.Next, we will explore how to correctly render Markdown content as HTML in the Anqi CMS template

2025-11-07

How to use the `archiveDetail` tag to display images, view counts, and publishing time on the document detail page?

In website operation, the document detail page is the core area that attracts users and conveys information.A rich content, intuitive detail page, which can not only significantly improve user experience, but also has a positive push on search engine optimization (SEO).AnQiCMS provides a powerful `archiveDetail` tag that allows us to easily obtain and display various document information, such as images, view counts, and publication time.Next, we will explore how to skillfully use the `archiveDetail` tag in the document detail page

2025-11-07

How does AnQiCMS display the latest article list on the homepage?

The homepage is the first impression of visitors arriving at the website, and the timely update of the latest article list can effectively enhance the activity and user stickiness of the website.For users using AnQiCMS, displaying the latest list of published articles on the homepage is a basic and important feature, which can be easily achieved through the flexible template tags provided by the system.AnQiCMS with its efficient and customizable features provides users with an intuitive template system.You do not need to delve deeply into the complex backend code, just master its powerful template tag usage

2025-11-07

How to display a document list on the AnQiCMS website based on a specific category ID?

In AnQiCMS, displaying a document list based on a specific category ID is a very basic and commonly used feature, which allows us to flexibly organize and present website content.AnQiCMS's powerful template tag system makes this operation intuitive and efficient.No matter where you want to manually insert a category of documents on a page, or want the entire category page to automatically display the documents under it, the system provides the corresponding solutions.

2025-11-07

What ways does AnQiCMS support for sorting the article list display, such as by views or publication time?

The display order of the website content list is one of the key factors affecting user experience and content operation effects.An excellent CMS system should provide a flexible sorting mechanism, allowing operators to freely adjust the display of articles according to content characteristics and promotion strategies.AnQi CMS deeply understands this, providing users with various ways to sort article lists, helping you accurately control content exposure and traffic guidance.### Core Sorting Feature: The Powerful Application of `archiveList` Tag In AnQi CMS

2025-11-07

How to get and display the detailed content of the current article in AnQiCMS template?

Build a content-rich website, the article detail page is undoubtedly the core.It carries the most specific and valuable information on the website, and it is also one of the pages where users spend the longest time and interact most frequently.In AnQiCMS (AnQi CMS), with its flexible template engine and rich tag system, we can easily obtain and elegantly display the detailed content of the current article.

2025-11-07