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

Calendar 👁️ 62

Managing website content in AnQiCMS and providing users with a smooth browsing experience is one of the key factors in content operation.After a user reads a wonderful article, they often hope to be able to jump to related or consecutive content easily, and the "previous" and "next" navigation on the article detail page is an important function to meet this need.AnQiCMS provides simple and powerful template tags, allowing you to easily implement this feature on the article detail page.

Easily implement: Add navigation for the previous and next articles on the AnQiCMS article detail page

In your AnQiCMS site, the article detail page is the core area for users to gain a deeper understanding of the content.Generally, we would provide users with links to navigate to the previous or next related article at the bottom of the article content or near the sidebar.This not only improves the user experience, encourages them to discover more relevant content, but also effectively improves the page depth (Page Depth) of the website, and is very beneficial for search engine optimization (SEO).

AnQiCMS provides two very convenient template tags for this:prevArchiveandnextArchiveThey are used to retrieve the data of the previous and next articles of the current article.

It introduces the titles and links of the previous and next articles.

To display the title and link of the previous article, you can use the template file on the article detail page (usuallyarchive/detail.htmlor{模型table}/detail.html) like thisprevArchiveTags:

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

Here we use aifTo judge the statementprevDoes the variable exist. If it exists, it will display a link to an article (prev.Link) and the title (prev.TitleThe link to the previous article; if it does not exist, it means that the current article is already the first in the category, and then a prompt text can be displayed, such as 'There is no previous article.'

Similarly, to display the title and link of the next article, you can usenextArchiveTags:

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

This is also passed hereifthe statement to judgenextVariable, ensure that the link is displayed only when the next article exists, otherwise display 'No next article.'

To make the page layout neater, you usually place these two navigations in a container and add some descriptive text, the final effect may be something like this:

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

You can further beautify by using external CSS stylesarticle-navigation/prev-articleandnext-articleLayout and appearance of elements, to keep them consistent with your website design style

More available article information

Besides titles and links,prevArchiveandnextArchiveThe tag also provides other practical article information, you can also call it according to your design needs, for example, the article ID (Id), description (Description),and thumbnail (Thumb)et al. If you want to display thumbnails in navigation, you can write it like this:

{% nextArchive next %}
  {% if next %}
    <a href="{{next.Link}}">
      {% if next.Thumb %}<img src="{{next.Thumb}}" alt="{{next.Title}}" />{% endif %}
      <span>{{next.Title}}</span>
    </a>
  {% else %}
    <span>没有了</span>
  {% endif %}
{% endnextArchive %}

Here passnext.ThumbGet the thumbnail address and pass it throughnext.TitleAs an imagealtattributes to optimize the performance of images in search engines.

Enhance user experience and SEO effects

This navigation method not only improves the user's browsing experience, encourages them to discover more related content, but also effectively improves the page depth of the website (Page Depth), and is very beneficial for search engine optimization (SEO).A well-structured internal link can help search engine spiders better crawl and index your website content, thus potentially bringing better rankings.

Implementing the navigation function for the previous and next articles in AnQiCMS, it can be completed with just a few lines of simple template code, which fully reflects the flexibility and ease of use of AnQiCMS in content management.


Frequently Asked Questions (FAQ)

1. Why did I add the code but the previous/next article did not display on the page?After modifying the template file, if the front-end page does not take effect immediately, the most common reason may be that the system cache has not been updated in time.You can try to go to the AnQiCMS background, click the "Update Cache" function in the left menu, clear the system cache, and then refresh the page to see the effect.In addition, make sure that your code is added to the correct template file that is being used on the article detail page, for examplearchive/detail.htmlOr the article template you customized.

2. What will happen if my article does not have a previous or next article? prevArchiveandnextArchiveWhen a tag does not have a corresponding previous or next article, its internal variables (such asprevornext) will be empty. The code examples provided in the article already contain{% if prev %}This condition judgment, in this case, it will elegantly display "none" or a custom prompt message without causing the page to error or display blank.

3. Can I use these tags on non-article detail pages? prevArchiveandnextArchiveTags are designed specifically for article detail pages. They depend on the context of the current page's article to determine which article is the "previous" and "next" article.Therefore, using them on non-article detail pages (such as the homepage, category list page, or single page) may not retrieve the correct article data, or the content may not be displayed at all.If you need to get a list of articles or a specific article on other pages, you should use a more generalarchiveListTags, and filter and display content through their parameters.

Related articles

How to implement pagination for article lists in AnQiCMS templates?

Good, as an experienced website operations expert, I know that implementing pagination for the article list in AnQiCMS not only improves user experience and makes content browsing smoother, but also helps with search engine optimization, allowing website content to be indexed better.Next, I will combine the AnQiCMS template mechanism and explain in detail how to easily implement this feature.

2025-11-07

How to display the article list on the AnQiCMS website and support sorting by publish time in descending order?

When running a website, effectively displaying a content list is a key factor in attracting visitors and enhancing user experience.For friends using AnQiCMS, the system provides very flexible and powerful template functions, which can easily meet various complex content display needs.Today, let's discuss how to display the article list on the AnQiCMS website, ensuring that the articles are sorted from the most recent to the oldest in publication time, while also supporting friendly pagination features.AnQiCMS's template system borrows the syntax of Django template engine

2025-11-07

How to safely display user-entered HTML content (such as article text) in AnQiCMS templates?

In website content operations, displaying user input information is one of the core functions, especially like the main text of articles that may contain rich formatting content.However, how to safely and accurately present these user-entered HTML content on the website while preventing potential security risks (such as cross-site scripting XSS attacks) is a problem that every website operator needs to think deeply about.AnQiCMS provides flexible and powerful tools for template design and content processing to meet this challenge.### AnQiCMS's default security mechanism: automatic escaping is the cornerstone AnQiCMS

2025-11-07

How to get and display the contact phone number and address set in the AnQiCMS template?

It is crucial to clearly and accurately display contact information in website operations to enhance user trust and promote communication and exchange.AnQiCMS provides a convenient backend setting and template calling mechanism, allowing you to easily manage and display this key information.This article will introduce in detail how to configure contact phone numbers and addresses in the AnQiCMS backend, as well as how to obtain and flexibly display this content in website templates.--- ### One, configure the contact phone number and address in the AnQiCMS backend Firstly, we need to configure in AnQiCMS

2025-11-07

How to retrieve and display related article lists based on the current article in AnQiCMS template?

How to intelligently display related article lists in the AnQiCMS template?After we publish an excellent article, it is natural for us to hope that readers will continue to browse more interesting content on the website.This involves the skill of displaying the 'related articles' list at the bottom of the article detail page.A highly recommended relevant article, not only can it effectively extend the user's stay on the website, improve user experience, but also has great benefits for the website's SEO optimization and content in-depth mining.AnQiCMS (AnQiCMS) knows this and provides a very concise and efficient template tag for it

2025-11-07

How to create a multi-level navigation with secondary dropdown menus in the AnQiCMS website navigation?

In website operation, a clear and efficient navigation system is the key to user experience and an important part of search engine optimization.AnQiCMS provides flexible navigation settings, allowing website administrators to easily create and manage multi-level navigation menus, including support for secondary dropdown menus.Next, we will learn together how to achieve this goal in AnQiCMS. ### Step 1: Configure the navigation link in the background First, you need to log in to the AnQiCMS backend management interface and enter the navigation settings module.

2025-11-07

How to display the breadcrumb navigation path of the current page in AnQiCMS template?

In website operation, a clear navigation path is crucial for user experience.Breadcrumb Navigation is like a clue in real life, clearly showing the user's current position on the website, allowing them to easily see where they are and quickly return to the previous or higher-level page.This not only helps users quickly understand the website structure and improve user experience, but also greatly benefits search engine optimization (SEO), as it helps search engines better understand the hierarchical structure of the website. AnQiCMS

2025-11-07

How to display all articles under a specific category in the AnQiCMS template?

When building a website with AnQiCMS, we often need to make the page content more flexible to meet the display needs of different blocks.One of the most common needs is how to accurately display a list of all articles under a specific category in the template.AnQiCMS with its efficient architecture based on the Go language and similar Django template engine syntax makes this task both intuitive and powerful.

2025-11-07