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

Calendar 👁️ 58

In AnQi CMS, adding links to the previous and next articles on the article detail page is a very practical feature for enhancing user reading experience and website internal link structure.The powerful template tag system of AnQiCMS makes it intuitive and efficient to implement this feature.

AnQiCMS Template Mechanism Overview

AnQiCMS uses a template engine syntax similar to Django, which means you can output content in your template files by{{变量}}to output content through{% 标签 %}Call the system function or execute logic. For the article detail page, AnQiCMS has built-in very convenient tags that can intelligently identify the current article and automatically retrieve the information of the previous and next articles.These tags allow you to indetail.htmlOr customize the article detail template to flexibly display navigation links.

Core:prevArchiveandnextArchiveTag

AnQiCMS provides two tags specifically used to implement the previous and next article functions.prevArchiveandnextArchiveThey are responsible for retrieving the complete data of the previous and next articles of the current article.These tags are very smart, you do not need to manually pass the current article ID or other complex parameters, they will automatically work in the context of the article detail page.

When you useprevArchiveWhen labeling, it will provide an object namedprev(this variable name can be customized), this object contains all the information of the previous article, such as the title of the article,Title), link (Link)ID(Id)as well as the thumbnail (Thumbetc. Similarly,nextArchiveThe tag will provide anextobject that contains the corresponding information for the next article.

How to add a link to the article detail page

To add these navigation links to your article detail page, you need to edit the corresponding article detail template file. Usually, the article detail page template file is located under the current theme of your website.模型table/detail.htmlFor examplearticle/detail.htmlorproduct/detail.html.

After you open your template file, you can find the appropriate place to insert links to the previous and next articles, such as below the article content or above the comment area.

First, you can useprevArchiveLabel to retrieve information about the previous article and ensure that the link is displayed only when there is a previous article:

{% prevArchive prev %}
<div class="prev-article">
    {% if prev %}
        <a href="{{ prev.Link }}" title="{{ prev.Title }}">
            <i class="icon-arrow-left"></i>
            上一篇:{{ prev.Title }}
        </a>
    {% else %}
        <span class="no-article">没有上一篇文章了</span>
    {% endif %}
</div>
{% endprevArchive %}

Right after that, you can use a similar method to add the link to the next article:

{% nextArchive next %}
<div class="next-article">
    {% if next %}
        <a href="{{ next.Link }}" title="{{ next.Title }}">
            下一篇:{{ next.Title }}
            <i class="icon-arrow-right"></i>
        </a>
    {% else %}
        <span class="no-article">没有下一篇文章了</span>
    {% endif %}
</div>
{% endnextArchive %}

In the code above,{% if prev %}and{% if next %}This judgment statement is very important. It ensures that when the article is the first in a series (without a previous one) or the last (without a next one), the page will not display empty links but will show friendly prompts, which greatly enhances the user experience.

Enhance display: add thumbnails and more information

In addition to simple titles and links, you can also make use ofprevandnextThe object contains rich information, making the navigation link more attractive. For example, you can choose to display the article thumbnail:

{% prevArchive prev %}
<div class="prev-article-card">
    {% if prev %}
        <a href="{{ prev.Link }}">
            {% if prev.Thumb %}
                <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}">
            {% endif %}
            <p>上一篇</p>
            <h3>{{ prev.Title }}</h3>
        </a>
    {% else %}
        <span class="no-article">没有上一篇文章了</span>
    {% endif %}
</div>
{% endprevArchive %}

{% nextArchive next %}
<div class="next-article-card">
    {% if next %}
        <a href="{{ next.Link }}">
            {% if next.Thumb %}
                <img src="{{ next.Thumb }}" alt="{{ next.Title }}">
            {% endif %}
            <p>下一篇</p>
            <h3>{{ next.Title }}</h3>
        </a>
    {% else %}
        <span class="no-article">没有下一篇文章了</span>
    {% endif %}
</div>
{% endnextArchive %}

By this method, users can preview the content of the next article more intuitively, thereby increasing the click-through rate. You can further utilize this according to your actual design needs.prev.Description/prev.CreatedTimefields to build richer and more personalized navigation elements.

integrate into your template.

add these code snippets to your.detail.htmlAfter the template file, you may also need to beautify the display effect of these links according to the overall style of the website. For example, you can set.prev-articleand.next-articleAdd floating, margins, background colors, and other styles to make it coordinated with the article content area and clearly presented as a navigation element.

After you complete the template modification and save, refresh your article detail page, and you will see that these features have taken effect.By using AnQiCMS template tags, the navigation links for the previous and next articles are realized, which is not only powerful but also easy to operate, greatly facilitating the management of website content and optimizing the user experience.


Frequently Asked Questions (FAQ)

Q1: If my article is the first or last in a series, and there is no previous or next article, what will be displayed?A1: In the above code example, we used{% if prev %}and{% if next %}Make a judgment. This means that if the current article does not have a previous one, it will display 'There is no previous article';If there is no next article, then it shows "No next article."You can customize these prompts according to your needs.

Q2: Why doesn't the link to my previous/next article display the image?A2: Whether the image is displayed in the link depends on whether you have used the template code.prev.Thumbornext.Thumbfield to retrieve images, and whether the article itself has uploaded a thumbnail. If the article does not have a thumbnail, even if the code usesprev.ThumbThe image cannot be displayed. Please check the editing page of the article to ensure that the thumbnail has been uploaded.

Q3: How to adjust the display style of the previous/next article link (such as layout, font size, etc.)?A3: In the above code example,divelements such asdiv class="prev-article") is an HTML structure, its appearance can be controlled by CSS stylesheets. You can add or modify the corresponding style rules for these class names or elements in the current theme's CSS file, such as adjustingfont-size/margin/padding/coloras well asdisplayProperties to change the layout.

Related articles

What are the commonly used fields that can be called with the `archiveDetail` tag on the article detail page?

AnQiCMS (AnQiCMS) provides great convenience for website operators with its flexibility and powerful content management capabilities.When we carefully craft an article or product page and hope to accurately display its colorful content to visitors, the `archiveDetail` tag is an indispensable tool at our disposal.It is like a treasure trove of information, allowing us to easily call up all related data of the current content on the article detail page.

2025-11-07

How to retrieve the list of articles under a specified category and implement pagination in AnQiCMS?

In website content operation, we often need to display articles under specific categories and provide pagination for these lists to enhance user experience and website loading efficiency.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag system can easily meet this requirement. AnQiCMS template system adopts syntax similar to Django template engine, using double curly braces `{{variable}}` to reference variables, as well as single curly braces with a percent sign `{% tag %}` to call tags.This makes the customization of content display very intuitive

2025-11-07

How to use the `archiveList` tag to display the latest article list on the AnQiCMS homepage?

On AnQiCMS, the homepage is often the first window visitors use to understand the website's content.How to efficiently and dynamically display the latest articles to attract visitors to continue browsing is the key to content operation.AnQiCMS provides a flexible and easy-to-use template tag system, where the `archiveList` tag is the core tool to achieve this goal.

2025-11-07

How to customize variables and assign values using (with/set) in AnQiCMS templates?

In AnQiCMS templates, flexibly customizing and using variables is the key to achieving dynamic content and efficient template reuse.AnQiCMS's template syntax borrows the characteristics of popular template engines such as Django and Blade, making variable definition and assignment intuitive and powerful.This article will deeply explore the `with` and `set` tags, helping you to better customize variables and utilize them in AnQiCMS templates.### One, the foundation of variable customization: Understanding the core of template syntax In AnQiCMS template

2025-11-07

How to use the `userDetail` tag to obtain and display the ID information of a specified user?

AnQiCMS with its flexible and powerful template tag system makes the display of website content very convenient.Whether it is articles, products, or user information, they can be easily displayed on the page with simple tags.Today, let's talk about how to use the `userDetail` tag to accurately obtain and display the ID information of a specified user.

2025-11-07

How to correctly display the user's `UserName` (username) in the AnQiCMS template?

In AnQiCMS templates, flexibly displaying user information is a key link to enhance website personalization and user experience.Whether it is to display the nickname of the comment author or to show the detailed information of the registered user on a specific page, it is very important to understand how to correctly call `UserName`. AnQiCMS's powerful template engine provides multiple ways to achieve this goal, and we will delve deeper into these methods next.AnQiCMS's template system adopts a syntax similar to the Django template engine, which allows developers to quickly build pages in a concise and efficient manner

2025-11-07

How to use the `userDetail` tag to retrieve the user's real name `RealName` on the frontend page?

In website operations, personalization and user experience are the key to enhancing brand image.Sometimes, we are not satisfied with just displaying the user's nickname or avatar. In certain scenarios, such as the member center, profile page, or some activity leaderboard, we may also need to display the user's real name.AnQi CMS is a highly flexible and feature-rich Go language content management system that provides intuitive template tags, allowing front-end developers to easily retrieve and display this information.Today, let's delve into how to use the `userDetail` tag of Anqi CMS

2025-11-07

The `userDetail` tag supports which parameters to accurately find specific user information?

In AnqiCMS template development, to display specific user information on the page, we often use a very practical tag - `userDetail`.This tag allows us to accurately retrieve and present detailed user data based on specific conditions.Understanding the parameters it supports is crucial for flexibly building user-related page functions.The core function of the `userDetail` tag is to obtain data based on a clear user identifier.When in use, it requires us to specify the user ID to be queried through the `id` parameter

2025-11-07