How to get and display the previous and next article links of AnQiCMS articles?

Calendar 👁️ 85

In website content operation, guiding users to smoothly browse related content is a key link to improving user experience and website depth.After a user finishes reading an article, if they can immediately see links to related or sequential previous and next articles, it will undoubtedly encourage them to continue exploring. This not only helps to reduce the bounce rate but also effectively improves the website's PV (page views) and SEO performance.AnQiCMS (AnQiCMS) is an efficient content management system that provides a very convenient way to implement this feature.

In AnQi CMS, it is much simpler than you imagine to obtain and display the links to the previous and next articles, which is mainly due to the built-in system featuresprevArchiveandnextArchiveThese are powerful template tags. These tags are designed to be very intuitive, and when you use them on the article detail page, they will automatically find and provide data for adjacent articles based on the current article's sorting in the list.

UnderstandingprevArchiveandnextArchiveTag

prevArchiveThe tag is used to get the information of the previous article of the current article, andnextArchiveTags are used to retrieve information about the next article. They do not require any additional parameters to specify the article ID because they will automatically identify the current article in the context of the article detail page and find the adjacent articles.

When using these tags, you need to use a variable to receive the article data they return. For example, we can assign the data of the previous article toprevVariable, assigning data to the next articlenextVariable.

{% prevArchive prev %}
{% nextArchive next %}

It is noteworthy that you may encounter some articles that are the first or last in a series, in which case there is no previous or next article.In order to avoid displaying empty links, we need to make a simple judgment when using these variables.

Information about the articles that can be obtained

Variables obtained through these two tags (for example, those we defineprevornext), you can access a series of information about adjacent articles, which is very similar to the details of the articles obtained througharchiveDetailtags. The most commonly used and core ones include:

  • Id: The unique identifier ID of the article.
  • Title: The title of the article.
  • Link: The access link of the article.
  • Thumb: The thumbnail address of the article, if set.
  • Description: The brief description or summary of the article.
  • Views: The number of views of the article.

You can use it to{{变量名.字段名}}to call this information, for example,{{prev.Title}}It will display the title of the previous article,{{next.Link}}will provide a link to the next article.

How to display previous/next article links on the article detail page

Now, let's integrate these knowledge points and see how to actually operate in your article detail page template.This code is usually placed at the bottom of the article content or in some sidebar position, so that users can easily proceed to the next step after reading the current content.

Assuming your template file isarchive/detail.html(This is one of the default naming rules of AnQi CMS article detail page template), you can add the following code snippet to it:

{# 假设我们正在文章详情页,这里会自动获取当前文章的上一篇和下一篇数据 #}

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

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

In this code, we first use{% prevArchive prev %}and{% nextArchive next %}The data of the previous and next articles were obtained and assigned separatelyprevandnextVariable.

Then, we use{% if prev %}and{% if next %}such conditional judgment to check if these variables exist. If they exist, we proceed through<a>Label to construct a clickable navigation with a title and link. If it does not exist, display a prompt message like 'No previous post' or 'No next post'.

You can optionally add a thumbnail image to the design of the template ({{prev.Thumb}}or{{next.Thumb}}) to make navigation more visually appealing. For example:

{# 在链接内部添加缩略图,如果存在的话 #}
{% if prev.Thumb %}
    <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="pagination-thumb">
{% endif %}

In this way, Anqi CMS can help you easily achieve seamless navigation between articles, enhancing the content browsing experience of users on your website.It fully utilizes the efficient processing capabilities and flexible template mechanism under the Go language architecture, allowing content operators to focus more on the content itself rather than complex code implementation.


Frequently Asked Questions (FAQ)

  1. What is the basis for determining the previous/next article?The previous and next article features of Anqi CMS usually depend on the publication time of the article(CreatedTime)or the sorting rules of the system backend to determine the logical sequence of the articles.This means that if your articles are arranged in a category in reverse chronological order, then 'Previous article' usually refers to the article published earlier, and 'Next article' refers to the article published more recently.In the context of the article list, they will determine the adjacent relationship according to the natural sorting in the list.

  2. If I want to jump to the previous/next article only within the same category, can this tag achieve that? prevArchiveandnextArchiveWhen the tag is used on the article detail page, it will default to trying to retrieve articles adjacent to the current article in the same context (usually the same category or the same list) according to the sorting rules.This means that if you are entering the article detail page from a list of articles in a certain category, then the previous/next articles returned by these tags will usually be limited to that category.

  3. How to customize the display style of the previous/next link?You can fully customize the style of the previous/next link with CSS. In the above example code, we usedarticle-pagination/prev-article/next-articleWait for CSS class names, you can design your website according to your own, write style rules for these classes in the CSS file, including font size, color, icons, layout, even animation effects, etc., to ensure they are consistent with your website's overall style.

Related articles

How to implement Markdown format content rendering and display on the AnQiCMS web page correctly?

In the digital age, the efficiency of content creation and publishing is the key to the success of the website.Markdown as a lightweight markup language, with its concise and efficient features, is increasingly favored by content creators.AnQiCMS knows this need, providing excellent Markdown support to users, making content creation more convenient, while ensuring that the web page presents a beautiful and clear structure.

2025-11-07

How to ensure that the encoding of AnQiCMS template files is correct to avoid page garbled characters?

When using AnQiCMS to build a website, we may encounter abnormal display of pages, with garbled characters.This is usually due to incorrect encoding settings in the template file.Ensure that the template file uses the correct encoding is a key step to avoid such problems, ensure the normal operation of the website, and provide a good user experience.AnQiCMS as a modern content management system, its internal processing and recommendation standards tend to use UTF-8 encoding.UTF-8 is an international character encoding that can be compatible with the characters of most languages in the world, including Chinese

2025-11-07

How to flexibly display custom content model fields on the front page of AnQiCMS?

In the world of content management, flexibility is the key to website success.Most of the time, we find that the standard "article" or "product" content model cannot fully meet our unique business needs, such as the need to add unique attributes such as "material", "size", etc. for a specific type of product, or to add information such as "registration deadline", "event location", etc. to the activity detail page.At this moment, the powerful custom content model function of AnQiCMS can fully show its strength.

2025-11-07

How to use the AnQiCMS Tag feature to associate and display related documents?

In today's increasingly complex content management, how to efficiently organize and present website content, allowing users to easily find the information they are interested in, while also improving the website's search engine performance, is a problem that every website operator is thinking about.AnQiCMS provides a series of powerful features to meet these challenges, among which, the Tag feature is undoubtedly a great tool for connecting and enriching content relationships.Tag, in the literal sense, is like various small tags attached to articles or products, which can cross traditional classification boundaries and bring together topics with the same theme

2025-11-07

How to use the pagination tags of AnQiCMS to control the display of list content?

In a content management system, how to effectively display a large amount of information without sacrificing user experience is always a question worth pondering.AnQiCMS provides a powerful and flexible pagination feature that allows website managers to finely control the display of list content, ensuring that the website is both beautiful and efficient.

2025-11-07

How to display custom Banner images on AnQiCMS pages?

In website operation, skillfully using Banner images can not only beautify the page but also effectively convey information and guide user behavior.AnQiCMS as a flexible content management system, provides various ways to display customized Banner images, allowing you to configure them individually according to different pages and needs. ### Flexible Upload and Management of Banner Images Firstly, all images that are going to be used as banners need to be uploaded to the AnQiCMS media library.This is very simple, you can go to the 'Page Resources' menu in the backend

2025-11-07

How to display AnQiCMS single-page content and related images?

In website operation, we often need to create some independent pages, such as "About UsThese pages contain relatively fixed content, do not belong to the conventional article or product list, AnQiCMS (AnQiCMS) classifies them as "single page" and provides a very convenient management and display method.Through this system, you can easily publish and update this content, while flexibly controlling their display styles and image presentation.

2025-11-07

How to display category introduction, Banner image and thumbnail on AnQiCMS category page?

In website operations, the category page is not only an aggregation of content, but also an important entry for users to understand the website structure and explore specific topics in depth.A well-designed, informative category page that can significantly improve user experience and search engine optimization (SEO) effectiveness.AnQiCMS provides flexible features, allowing us to easily display category descriptions, banner images, and thumbnails on the category page, giving your website's category page a fresh look.Understanding AnQiCMS's category page and template structure In AnQiCMS

2025-11-07