How to get the title of the previous article in the AnQiCMS template?

Calendar 👁️ 68

In website content operation, providing users with a smooth reading experience is the key to enhancing user stickiness.When the reader is immersed in an excellent article, it is natural to want to easily jump to related content, especially the previous or next one.It is not difficult to achieve this in AnQiCMS, such an efficient and customizable content management system.Today, let's delve into how to cleverly retrieve and display the title of the previous article in the AnQiCMS template.

AnQiCMS template: Intuitive and flexible integration

AnQi CMS with its high-performance architecture based on the Go language provides a concise and powerful content management capability.On the template level, it adopts a syntax similar to the Django template engine, which is undoubtedly a great convenience for operators or front-end engineers familiar with web development.Through double curly braces{{变量}}Get variable value, as well as single curly braces and percent signs{% 标签 %}Perform logical control or call specific functions, AnQiCMS makes template creation both intuitive and flexible.

To obtain the title of the previous article, we mainly rely on the built-in "Template Tag" feature of AnQiCMS.These tags are like pre-set functions that can help us easily extract the required data from the database and display it in the way we want.

Core revelation:prevArchiveThe use of tags

In AnQiCMS, there is a tag specifically used to get information about the previous article of the current article.prevArchive. This tag is very smart, it can automatically find and return the previous article in the same category as the article being browsed.

Basic usage method

prevArchiveThe label usage is very concise and clear. You need to wrap it using{% prevArchive 变量名 %}such a structure, where变量名is a temporary variable you define for the data of the last article you got, for exampleprev.

This is a basic example:

{% prevArchive prev %}
    <!-- 在这里可以访问 prev 变量中的上一篇文章信息 -->
{% endprevArchive %}

OnceprevOnce a variable is assigned, you can access its properties through the dot (",.) such as the title, link, thumbnail, etc.

Get the title and link of the previous article

The most common requirement is to display the title of the previous article and provide a jump link.prevArchiveTags providedTitle(Title) andLink(Link) these two core attributes.

However, we first need to consider a practical situation: the current article may already be the first article in the category, in which case there is no "previous article". Therefore, a conditional judgment should be added to the template.{% if prev %}It is very important, this can ensure that the display is only performed when the previous article exists, thus avoiding the embarrassment of page errors or empty content.

This is a commonly used code snippet to get the title and link of the previous article:

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

In this code, we first use{% prevArchive prev %}Assign the data of the previous article toprevthe variable. Then, by{% if prev %}the judgment.prevCheck if it is empty. If it exists, we will use{{ prev.Link }}and{{ prev.Title }}Output the link and title of the previous article. If there is no previous article, then display the prompt 'There is no previous article'.This way, no matter on which article page, users can get a friendly navigation experience.

More practical information to obtain

Besides titles and links,prevArchiveTags also provide other practical fields, you can flexibly call them according to the design requirements of the website, for example:

  • Id.: The ID of the previous article.
  • Description.: The introduction of the previous article.
  • Thumb: The thumbnail address of the previous article.
  • CreatedTime: The publication time of the previous article (timestamp, usually obtained through){{stampToDate(prev.CreatedTime, "2006-01-02")}}for formatting).

For example, if you want to display a thumbnail next to the title:

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

In this way, you can freely organize and display various information of the previous article according to the page layout and user experience requirements.

Combine with the navigation of the next article to create a complete experience.

Generally, at the bottom of the article detail page, we provide navigation to the previous and next articles to form a complete reading loop. AnQi CMS also provides the correspondingnextArchiveTags, their usage isprevArchiveidentical.

Combine both, and you can build a perfect navigation block:

<div class="article-pagination-nav clear">
    <div class="prev-article-link float-left">
        {% prevArchive prev %}
            {% if prev %}
                <span class="nav-label">上一篇:</span>
                <a href="{{ prev.Link }}" title="{{ prev.Title }}" class="nav-title">
                    <i class="icon-arrow-left"></i> {{ prev.Title|truncatechars:35 }}
                </a>
            {% else %}
                <span class="nav-label">上一篇:</span><span class="nav-none">没有了</span>
            {% endif %}
        {% endprevArchive %}
    </div>
    <div class="next-article-link float-right text-right">
        {% nextArchive next %}
            {% if next %}
                <span class="nav-label">下一篇:</span>
                <a href="{{ next.Link }}" title="{{ next.Title }}" class="nav-title">
                    {{ next.Title|truncatechars:35 }} <i class="icon-arrow-right"></i>
                </a>
            {% else %}
                <span class="nav-label">下一篇:</span><span class="nav-none">没有了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

Here we also used an extratruncatechars:35A filter used to automatically truncate and add an ellipsis when the title is too long to maintain a neat page layout, which is especially important on mobile devices.This navigation is not only functional, but also greatly enhances the discoverability of website content and the user's reading experience.

Summary

To get the title of the previous article in AnQiCMS, it is throughprevArchiveThis powerful and intuitive template tag implementation. Combined with simple conditional judgments, you can not only ensure the robustness of navigation, but also display more information as needed, such as links, thumbnails, and even withnextArchiveBuild a seamless content navigation experience together. Anqi CMS is committed to providing highly customizable solutions, and these template tags are just the embodiment of its flexibility, helping content operators to efficiently improve the user experience of the website.


Frequently Asked Questions (FAQ)

How to get the title of the next article?

To get the title of the next article, you can use withprevArchivethe label that corresponds to thenextArchivelabel. The usage is similar to:

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

2. If the current article is the first in the category,prevArchivewhat will be displayed?

If the current article is the first article in its category, thenprevArchiveThe tag will not find the corresponding previous article, at this point we set upprevThe variable will be null (nil). Therefore, we usually use it in the template{% if prev %}to make a judgment. WhenprevWhen empty, it will execute{% else %}The content in the code block, for example, displaying a prompt information such as 'No previous article' to maintain the integrity and user experience of the page.

3. In addition to the title, what other information about the previous article can I obtain?

In addition to the title (Title) you can also useprevvariables to obtain various properties of the previous article, such as:

  • Link: The full link of the article.
  • Id: The unique ID of the article.
  • Description: The brief description of the article.
  • Thumb: The thumbnail of the article.

Related articles

Does AnQiCMS support setting the page number range (such as only displaying N pages before and after the current page)?

## Fine control of browsing rhythm: AnQiCMS pagination tag page number range setting analysis In the world of content management and website operations, an efficient and user-friendly pagination system is crucial for improving user experience and optimizing search engine crawling efficiency.AnQiCMS, as an enterprise-level content management system based on the Go programming language, deeply understands this, and has provided us with a flexible and powerful pagination function.

2025-11-07

How to ensure that the pagination navigation is aligned and laid out correctly at the bottom of the AnQiCMS page?

As an experienced website operations expert, I am well aware of the importance of pagination navigation in enhancing user experience and optimizing website structure.In an efficient and flexible content management system like AnQiCMS, ensuring that pagination navigation is not only functionally complete but also correctly aligned and elegantly laid out visually is an indispensable part of content operation.Today, let's delve into how to achieve this goal in AnQiCMS. ### AnQiCMS Pagination Mechanism Overview The core of pagination navigation in AnQiCMS is its powerful template tag system.When we process the article list

2025-11-07

Does AnQiCMS pagination tag internal rendering logic process links with `urlencode`?

As an experienced website operations expert, I know that every detail in a content management system can affect the performance, user experience, and even search engine optimization (SEO) of a website.Today, let's delve into whether the AnQiCMS pagination tag performs `urlencode` processing on its internal parameters when generating links, which is crucial for ensuring the robustness and correctness of the links.

2025-11-07

In the advanced usage of the `prefix` parameter, how to avoid errors caused by manually constructing complex URLs?

As an experienced website operations expert, I know that in daily work, the construction and management of URLs are the foundation of the healthy operation of the website.A clear, standardized, and search engine-friendly URL structure, which not only significantly improves user experience but is also the top priority of SEO optimization.

2025-11-07

How can you display the link to the previous document on the article detail page?

As an experienced website operations expert, I am well aware of the importance of navigation design on article detail pages for user experience and search engine optimization (SEO).A well-designed and functional detail page that not only guides users to explore more content, effectively reducing the bounce rate, but also helps to build a good site structure through internal links, aiding search engine crawling and ranking.AnQiCMS (AnQiCMS) with its high-performance architecture based on the Go language and flexible template mechanism, provides us with powerful and convenient tools to achieve these refined operational goals. Today

2025-11-07

What is the function and advantage of the `prevArchive` tag in Anqi CMS?

In the world of content operation, user experience and search engine optimization (SEO) are always the two fundamental cornerstones of website success.AnQi CMS, as an enterprise-level content management system built with Go language, deeply understands this, and helps operators easily achieve their goals through a series of simple and powerful features.Today, we will focus on a seemingly minor, but actually profound member of its template tag system - the `prevArchive` tag, discussing how it silently enhances the value of the website and provides readers with a more seamless browsing experience.

2025-11-07

What is the correct syntax and example of using the `prevArchive` tag?

## Smart Content Link Flow: Deep Analysis of the Correct Usage and Practice of AnQiCMS `prevArchive` Tag In the daily operation of AnQiCMS, we fully understand that providing users with a smooth reading experience is crucial for retaining visitors and enhancing the value of the website.A great website is not only rich in content, but also seamless in the connection between content, guiding users to naturally explore more information.Today, as an experienced website operations expert, I will take everyone to deeply understand AnQiCMS

2025-11-07

The `prevArchive` tag can retrieve which basic information of the previous document?

As an experienced website operations expert, I often deal with AnQiCMS (AnQiCMS) in my daily work and am well aware of the strong and flexible template tags.Today, let's delve into a crucial tag in content navigation - `prevArchive`, which helps us seamlessly jump to the previous document and provides some basic information about the previous document, making our website content operation more effortless.

2025-11-07