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

Calendar 👁️ 66

In website content operation, improving user experience and content browsing depth is indispensable.After a visitor reads an article, if they can easily browse to the titles and links of the 'previous article' and 'next article', it will undoubtedly greatly encourage them to continue exploring the website's content, thereby extending their stay time, reducing the bounce rate, and even having a positive impact on the overall SEO performance of the website.Anqi CMS as an efficient and customizable content management system, fully considers this user demand.

The Anqi CMS simplifies the implementation of this common website feature by providing intuitive and powerful template tags.This allows website operators to easily integrate navigation functions for the previous and next articles in the article detail page without deeply understanding complex programming logic.The core lies in two dedicated tags:{% prevArchive %}and{% nextArchive %}These tags were designed to facilitate the retrieval of adjacent articles to the current article in the time sequence.They can intelligently identify the article being browsed at the moment, automatically find the data of the previous and next articles, including the title and link, greatly reduce the burden of template development and content maintenance, and make the page content navigation extremely smooth.

You need to find the corresponding template file for the article details page to add these navigation items. In Anqi CMS, this is usually located in the current template directory.{模型table}/detail.htmlfile, for example, if your website uses an article model, then the file path might bearticle/detail.html. After opening this file, you can insert the corresponding template code at the location where you want to display the previous and next articles.

For example, you can use{% nextArchive next %}...{% endnextArchive %}Label. Here,nextis a temporary variable name we specify for the data of the next article. Inside this label,nextyou can access the properties of the object to obtain the required information, such as{{next.Title}}You can get the title of the next article,{{next.Link}}then you can get the link of the next article. Similarly, to get the "previous article", you use{% prevArchive prev %}...{% endprevArchive %}whereprevIs the variable name of the previous article, its attribute access method is the same asnextNamely,{{prev.Title}}and{{prev.Link}}.

In practical applications, it is necessary to consider whether the article is the first in the category (without a previous one) or the last (without a next one).We usually combine conditional judgment to avoid displaying empty links or unfriendly prompts.{% if next %}(or{% if prev %}To check if adjacent articles exist, and only display the title and link if they do; otherwise, a prompt text such as 'None' can be displayed, or the navigation item can be displayed according to design requirements.

Here is a simplified code example of integrating navigation for the previous and next articles in an article detail page template:

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

This code first creates two areas, one for navigating to the previous article and the next article. Inside each area, throughprevArchiveornextArchivetag wrapping logic, then through{% if ... %}the judgment.prevornextThe variable is empty. If there is an adjacent article, its title and link will be displayed;If not available, a prompt displaying "none" will be shown. This approach ensures both the integrity of the function and the friendliness of the user interface.

In addition to the basic display, you can also beautify these navigation bars through CSS styles to keep them consistent with the overall design style of the website, for example, by adding icons, adjusting font size or color, or designing them as left and right arrow shapes to enhance the visual navigation effect.The implementation of this feature not only improves the average browsing depth of visitors on the website and reduces the bounce rate, but also provides strong support for search engine optimization (SEO).When evaluating website quality, search engines consider user behavior metrics, and smooth in-site navigation and longer user stay times can send positive signals to search engines.

The AnQi CMS provides such concise and powerful template tags, allowing content operators to focus on content creation and the overall design of the website without being troubled by complex code logic.It truly hides the technical details behind the scenes, allowing users to easily implement features and optimize website performance.


Frequently Asked Questions (FAQ)

  • 1. Why did I add code to the article detail page, but the links to the previous/next article did not display?This may have several reasons. First, please check if the current article is the first one in the category (without a previous one) or the last one (without a next one), in which case, the corresponding navigation links will naturally not be displayed.Secondly, ensure that you have saved and deployed the modified template file and cleared the system cache.Finally, check for spelling errors in the template code, especiallyprevArchive/nextArchivetags as wellLink/TitleProperty names, they are case sensitive.

  • 2. What are the sorting rules for the previous and next articles? Can I customize it?The previous and next article tags of AnQi CMS are usually based on the publication time of the article, usuallyCreatedTimeSorted by time, the earlier one is the previous article, and the later one is the next article. Currently,prevArchiveandnextArchiveThe label itself does not provide a parameter for direct customization of sorting rules. If you have special sorting requirements, you may need to go through secondary development or utilizearchiveListTo implement combined with more complex logic, but this will be more complex than using these two tags directly.

  • 3. I want to display custom prompts when there is no previous/next article, instead of 'No more', or simply not display this part of the navigation. How can I do that?You can fully customize. In the above code example,{% else %}the part is used to handle cases without adjacent articles. You can use<span>上一篇:没有了</span>Replace with any text content or HTML structure, for example `← It is already

Related articles

How to call the category list and display the number of articles under it in AnQiCMS template tags?

In a content management system, effectively organizing and displaying content is the key to improving user experience and website SEO performance.AnQiCMS provides powerful and flexible template tags, allowing developers to easily build richly functional page layouts.Among them, calling the category list and displaying the number of articles under it is a very common and practical demand in website navigation and content overview.This not only helps users quickly understand the content volume of each category, but also provides clear website structure information for search engines.<h3>Understanding `categoryList`

2025-11-08

How to use AnQiCMS's flexible content model to achieve personalized field display on product detail pages?

## Utilizing AnQiCMS flexible content model, create uniquely crafted product detail pages When operating a website, we all hope that product detail pages can attract visitors and provide clear, personalized product information.However, when facing different types of products, using a fixed template alone often fails to fully showcase their unique features, and may even make visitors feel that the information is insufficient or confusing.For example, the display parameters required for a mobile phone and a T-shirt are completely different, forcing a template will only make things twice as difficult.

2025-11-08

How to optimize the SEO-friendly URL of the article detail page through the pseudo-static function of AnQiCMS?

A clear, readable, and relevant URL address is crucial for a website's performance in search engines.It can not only help users understand the page content intuitively, but also assist search engines in accurately understanding and indexing your page.In AnQiCMS, to implement URL optimization for the article detail page, the static function is undoubtedly our helpful assistant.What is a static URL and why is it important?

2025-11-08

How to implement differentiated display of content for PC and mobile terminals in AnQiCMS templates?

In today's internet environment, providing a high-quality cross-device browsing experience is the key to the success of website operations, whether it is a corporate website, e-commerce platform, or personal blog.AnQiCMS (AnQi CMS) has fully considered this requirement in template design, providing users with flexible and diverse solutions to achieve differentiated display of content on PC and mobile endpoints.This is not just about adapting the interface layout, but also about how to present the most suitable content for users based on device characteristics.Next, we will delve into how the AnQiCMS template cleverly achieves this goal.

2025-11-08

How to set and display the website filing number and copyright information at the bottom of the AnQiCMS page?

The website's filing number and copyright information are important elements that demonstrate the compliance and professionalism of the website. They usually appear in the footer, providing visitors with a sense of trust.In AnQiCMS, setting and displaying this information is simple and efficient.We will guide you through this process, ensuring that the key content is clearly presented at the bottom of your website. ### Step 1: Set the record number and copyright information in the AnQiCMS background First, log in to your AnQiCMS background management interface. This is the starting point of the basic information configuration for all websites. 1. **Navigate to the global feature settings:**

2025-11-08

How to safely output article content containing HTML tags in AnQiCMS templates (to prevent XSS)?

When processing article content that contains HTML tags in AnQiCMS templates, securely outputting is a crucial issue, as it directly concerns the safety and user experience of the website.Especially when the content of the article may be input by the background rich text editor, or when comments and messages submitted by users contain custom HTML, improper handling is likely to be attacked by cross-site scripting (XSS).AnQiCMS as a content management system that focuses on security and efficiency, provides the corresponding mechanisms to help us meet this challenge.Understanding Risk

2025-11-08

How to enable automatic image compression and WebP format conversion in AnQiCMS to improve page loading speed?

In today's fast-paced online environment, website loading speed has become a key indicator of user experience and search engine rankings.If your website has many images, they may be slowing down your website speed quietly.Fortunately, AnQiCMS fully considers this point and provides us with automatic image compression and WebP format conversion functions, which can effectively accelerate page loading and make your website fly.Why is image optimization so important?\n\nImagine when a user visits a page, if the images take a long time to display or load slowly

2025-11-08

How to determine in the template whether the current page is an article detail page or a category list page, and display different content?

In the template development of Anqi CMS, it is a common requirement to display different content according to the type of the current page (whether it is an article detail page or a category list page).This not only makes the website user experience more personalized, but also provides more fine-grained control in SEO optimization.Luckyly, AnQi CMS's powerful template engine provides an intuitive way to determine the context of the current page and conditionally render accordingly.Understanding AnQi CMS template context The AnQi CMS template engine is very intelligent, it renders pages at runtime

2025-11-08