How to display the title and link of the previous and next articles on the article detail page?

Calendar 👁️ 71

In Anqi CMS, adding the titles and links of the previous and next articles to the article detail page can not only optimize the user's browsing experience on your website, guide them to discover more relevant content, but also improve the internal link structure of the website to a certain extent.AnQi CMS, with its concise and efficient template engine, makes this feature implementation very intuitive.

Core feature revelation: prevArchive and nextArchive tags

The Anqi CMS template system is built-in with two tags specifically for handling article navigation:prevArchiveandnextArchiveTheir function is self-evident—they are used to obtain the data of the previous and next articles of the current article.These tags are very smart, no complex parameter configuration is required, the system will automatically judge and retrieve the corresponding previous and next article information based on the current article ID.

Operation steps: Integrate the previous/next article into the detail page

Add this feature to your website, you need to modify the template file of the article detail page.

  1. Find your article detail page templateIn most cases, the template file of the article detail page is located at/templateFor example, in a model folder under the directorydefault/article/detail.htmlOr you can specify a custom template path.

  2. Insert the core code snippetIndetail.htmlIn the file, find the position where you want to display the previous/next article. Usually, they are placed at the bottom of the article content.

    First, let's add the link to the previous article. You can useprevArchivetags to get the data of the previous article, andifthe statement to determine if there is a previous article.

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

    Continue in a similar manner to add the link to the next article. UsenextArchivetags to get the data of the next article:

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

Complete code example

Integrate the two code snippets above into yourdetail.htmlIn the template, the effect may be as follows:

<article>
    <!-- 这里是文章详情页的其他内容,如标题、发布时间、文章内容等 -->
    <h1>{{ archive.Title }}</h1>
    <div>
        <span>发布时间:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}</span>
        <span>浏览量:{{ archive.Views }}</span>
    </div>
    <div class="article-content">
        {{ archive.Content|safe }}
    </div>

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

This code will first determine if there is a corresponding previous or next article.If it exists, it will display the article title and link to the article;If none, it will display a prompt indicating "none". You can adjust it according to your design needsdivandaStyle labels, even add thumbnails and other additional information.

Understanding how labels work.

prevArchiveandnextArchiveThe label can automatically identify the current article and find adjacent articles according to the order of the article ID (usually within the same category).This means they can also maintain correctness after your website content is updated, greatly reducing the cost of manual maintenance.They are a typical example of how Anqi CMS provides convenience in content operation efficiency.


Frequently Asked Questions (FAQ)

1. What if my article does not have a previous or next article?In the above example code, we used{% if prev %}and{% if next %}Such conditional judgment. If the current article does not have a previous (or next) one, thenprev(ornextThe variable will be empty, and it will display at this timeelseContent within the block, for example, "Previous: None." This ensures that the page displays elegantly when there are no adjacent articles, without any errors.

2. Can I customize the display style of the previous/next article? For example, can I add a thumbnail?Of course you can.prevandnextVariables not only containTitleandLinkbut also provide other fields, such asThumb(article thumbnail),Description(Article summary) and so on. You can add{% if prev %}or{% if next %}in the block, add<img>tags to display thumbnails or other additional information such as:

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

3. What rules are used to determine the previous/next article based on these tags? prevArchiveandnextArchiveLabels are usually determined by the publication order of the current article in the category it belongs to (usually in ascending or descending order by ID or publication time) to determine the previous and next articles.If the article does not belong to any category, or is searched globally, it will be searched according to the order of the global article ID.They are intended to provide the most direct content adjacent to the current article in sequence.

Related articles

How does the AnQiCMS template format timestamps and display them in a specified date and time format?

In AnQiCMS template, easily format timestamps: Custom date and time display guide In website operation, content publishing time, update time, comment time, and other date information are an important part of the information we convey to visitors.Most of the time, the time data obtained from the database is usually a timestamp (a string of numbers), which is not intuitive for users.How to convert these original timestamps into a readable date and time format, and flexibly adjust the display according to the page design, which is a frequently encountered demand in template development. AnQiCMS

2025-11-07

How to only display documents of the current category on the category list page and not include documents of subcategories?

When operating a website, we often encounter the need to display content, one common scenario being how to precisely control the displayed content on a category list page.Sometimes, we hope to display documents under a main category page, including all subcategory documents as well, to provide more comprehensive information.However, in some cases, in order to maintain the purity of the page theme and the focus of the content, we may only want to strictly display the documents under the current category without including any content from subcategories.AnQi CMS as a flexible content management system

2025-11-07

How is the 'Multi-site Management' feature of AnQiCMS implemented to display different site content independently?

## Deeply analyze the "Multi-site Management" feature of AnQiCMS: How to ensure independent display of content?How to efficiently manage content when operating multiple websites or owning multiple brand sub-sites, while ensuring the independence of content on each site, is a challenge faced by many operators.The "multi-site management" feature provided by AnQiCMS is designed to solve this pain point.It not only allows you to manage all sites in a single background, but also fundamentally ensures that the content of each site is displayed independently, avoiding confusion and errors.So, AnQiCMS

2025-11-07

How to set the display logic and hierarchy of breadcrumb navigation in AnQiCMS template?

When building a website, breadcrumb navigation not only effectively improves user experience and helps visitors understand their current location, but is also an indispensable part of search engine optimization (SEO), as it clearly shows the hierarchical structure of the website.For websites using AnQiCMS to manage content, flexibly setting the display logic and hierarchy of breadcrumb navigation is an important task in template creation.AnQiCMS provides a powerful and easy-to-use template tag for handling breadcrumb navigation, allowing you to easily implement it in the front-end template without writing complex backend logic

2025-11-07

How to implement batch replacement of specific keywords in article content and display it on the front end in AnQiCMS?

In the daily work of content operation, we often encounter the need to make uniform adjustments to a large amount of article content.This may involve updating the brand name, correcting industry terminology, unify the product model, and even adjusting keyword density for SEO purposes.Manually modifying hundreds or even thousands of articles one by one is undoubtedly a huge task and is prone to errors.AnQiCMS provides a very practical feature that can help us efficiently implement batch replacement of specific keywords in article content and ensure that these changes are displayed correctly on the website front-end.Why do you need to replace keywords in articles in bulk

2025-11-07

How to display custom field content of different content models in the frontend template?

The content model feature of AnQiCMS brings great flexibility to website operations, allowing us to define various personalized content structures according to our actual business needs.Whether it is an article, product, event, or any other custom content type, we can add unique fields for it.How can we flexibly display custom fields in the content model on the website front-end template?Let's explore this practical skill together. ### Understanding AnQiCMS's Content Model and Custom Fields Using AnQiCMS

2025-11-07

Does AnQiCMS website support automatically converting uploaded images to WebP format to speed up display speed?

The loading speed of a website is an important factor for user experience and search engine optimization.Among them, images play an important part in the page content, and their loading efficiency has a significant impact on the overall performance of the website.WebP is a modern image format, compared to traditional JPEG, PNG, it can provide similar or even higher image quality with smaller file size, thereby significantly speeding up web page loading speed.AnQiCMS as a content management system that focuses on efficiency and performance, fully considers the optimization needs of the website in image processing.For "AnQiCMS"

2025-11-07

How to display the name and link of the current article's category in a frontend template?

In website content operation, the classification information of articles not only helps users quickly understand the content attribution, but also is the key to improving the website navigation experience and search engine optimization (SEO) effect.For friends who use AnQiCMS to build websites, it is a very practical and basic requirement to accurately display the name of the category to which each article belongs and provide a link.AnQiCMS provides powerful and flexible template tags, allowing us to easily achieve this function.### Skillfully Utilize `archiveDetail`

2025-11-07