In AnQi CMS, how can the `Id` field of the previous document be retrieved through the `prevArchive` tag?

Calendar 👁️ 64

As an old soldier who has been deeply engaged in website operation for many years, I know that how to efficiently obtain and utilize content data in a content management system is crucial for improving user experience and website maintenance efficiency.AnQiCMS (AnQiCMS) boasts its concise and efficient features, providing many intuitive template tags to make content operation more flexible.Today, let's delve into a very practical scenario: how to use AnQiCMS byprevArchiveLabel to obtain the previous document'sIdfield.

How to cleverly get the previous document in AnQi CMSId?

When building website content, especially for blogs, news, or product detail pages, we often need to provide users with 'Previous' and 'Next' navigation links to guide users to continue reading and optimize the internal flow. Anqi CMS provides special template tags for this, whereprevArchiveThe tag is used to obtain the information of the 'previous' document of the current document.

Get to knowprevArchiveTag

prevArchiveThe design philosophy of the tag is to simplify operations as much as possible, it can automatically identify the context of the current page without passing any parameters, and try to get the document sorted before the current document.After successfully obtaining the previous document, it will fill all the relevant data of the document into a variable you specify, making it convenient for you to call it in the template.

For example, you can enable it in the template in the following way.prevArchiveTags:

{% prevArchive prev %}
{# 在这里,您就可以使用 'prev' 变量来访问上一篇文档的数据了 #}
{% endprevArchive %}

In this code block,prevIt is the variable name specified for the data of the previous document. Once the tag executes successfully,prevthe variable will become an object containing various properties of the previous document.

Get the previous document'sIdfield

SinceprevArchiveThe tag has placed all the available data from the previous document intoprevthe variable, so getting itsIdfield becomes extremely simple. You just need to use the dot.operator, and directly accessprevVariableIdproperties.

IdIs a unique identifier for each document in the Anqing CMS system, usually an integer.It is very useful for building dynamic links, performing backend data interaction, or handling specific logic in front-end JS.

The following is a document obtained and used in a real templateIdA complete example of a field:

{% prevArchive prev %}
{% if prev %}
    <div class="prev-document-navigation">
        <p>上一篇:
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                {{ prev.Title }}
                <small>(文档ID: {{ prev.Id }})</small>
            </a>
        </p>
    </div>
{% else %}
    <div class="prev-document-navigation">
        <p>上一篇:没有了</p>
    </div>
{% endif %}
{% endprevArchive %}

Let's parse this code step by step:

  1. {% prevArchive prev %}: This line of code indicates that the AnQi CMS should find the previous content of the current document and assign the found data to a variable namedprev.
  2. {% if prev %}: This is a very important judgment. It checksprevDoes the variable really have a value. If the current document is the first in the series, then there will be no previous document,prevThe variable will be empty. This judgment can avoid trying to access a non-existent field when there is no previous document, which may cause a page error.
  3. <a href="{{ prev.Link }}" ...>IfprevIf it exists, we can safely access its properties.{{ prev.Link }}The URL link of the previous document will be output,{{ prev.Title }}The title of the document will be output.
  4. <small>(文档ID: {{ prev.Id }})</small>: This is exactly the core we are looking for!{{ prev.Id }}The previous document will be output directly.IdField value. You can decide whether to display this on the front end based on your actual needsIdOr use it behind the scenes for other logical processing.
  5. {% else %}IfprevThe variable is empty, which means there is no previous document, and we then display a prompt such as 'No more' to ensure the integrity of the user experience.
  6. {% endif %}and{% endprevArchive %}: This is to distinguish between conditional judgments andprevArchiveThe end tag, ensuring the correctness of the template syntax structure.

By the above method, you can not only easily get the previous document,Idbut also getTitle/LinkOther commonly used fields to build a beautiful and functional page navigation.The template tag system of AnQi CMS is like this, through the intuitive variable call, it converts complex backend data processing into a simple and easy-to-understand frontend display.


Frequently Asked Questions (FAQ)

Q1:prevArchiveThe label can retrieve the current document'sId?A1: No.prevArchiveThe design purpose of the label is to obtain the information of the previous document, it only returns the data of the document immediately preceding the current document in the sorting sequence. To obtain the current document'sIdYou should directly use it in the detail page template.{{ archive.Id }}Assuming the current document variable is namedarchiveor{% archiveDetail with name="Id" %}such tags.

Q2: If my website has multiple content models or categories,prevArchivehow will the tags determine 'Previous post'?A2:prevArchiveLabels are usually located in the current document locatedthe same content model and classificationLooking for the previous document. This means that if you are currently browsing an article under the "Article Model" category of the "Technical Sharing" category,prevArchiveIt will look for the previous article adjacent to the document list of the "Article Model" under the "Technology Sharing" category. This ensures the consistency and relevance of navigation.

Q3: BesidesId,prevArchiveWhat are some common document fields that the tag can retrieve?A3:prevArchiveTags retrieved from comments.prevThe variable contains many useful fields from the previous document, but also includesIdYou can also directly access{{ prev.Title }}(Document Title),{{ prev.Link }}(Document Link),{{ prev.Description }}(Document description),{{ prev.CategoryId }}(Category ID),{{ prev.Views }}(Views),{{ prev.Logo }}(Cover main image),{{ prev.Thumb }}(Cover thumbnail) as well{{ prev.CreatedTime }}(Creation time) and so on. These fields are sufficient to meet the needs of most navigation and information display.

Related articles

What are the similarities and differences in the functionality between the `prevArchive` and `nextArchive` tags?

As an experienced website operation expert, I know how crucial it is to skillfully utilize each feature point in a high-efficiency content management system like AnQiCMS to optimize user experience and content management efficiency.Today, let's delve into the two navigation tools in Anqi CMS template tags that seem similar but have different missions: the `prevArchive` tag and the `nextArchive` tag, analyze their similarities and differences in function, and help you build a smooth website browsing experience.###

2025-11-07

How to use the `prevArchive` tag to display the thumbnail or cover image of the previous document?

## Enhance Content Relevance: Use the `prevArchive` tag in AnQiCMS to display the thumbnail or cover image of the previous document In today's increasingly fragmented content consumption, how to effectively guide users to browse more content, improve the stay time on the website, and enhance the user experience is a problem that every website operator needs to think deeply about.AnQiCMS as a highly efficient and customizable enterprise-level content management system provides many powerful template tags, making content operation and display extremely flexible. Today

2025-11-07

The `prevArchive` tag supports which parameters to filter or specify the previous document (the document mentions that no parameters are supported, but users may still ask)?

In AnQiCMS template development, the `prevArchive` tag is a very practical tool that can easily help us implement the navigation function of the "previous article" document on the article detail page, thereby optimizing the user's browsing experience.As a website operations expert, I fully understand the importance of smooth page transitions and convenient content discovery for user retention and SEO.However, whether the `prevArchive` tag supports parameters to filter or specify the previous document is often a question many users have when exploring the features of AnQiCMS

2025-11-07

How to elegantly display a 'none' prompt when there is no previous document for the `prevArchive` tag?

In the daily operation of AnQiCMS, the content detail page usually contains 'Previous' and 'Next' navigation for the convenience of users browsing.This is not only the key to improving user experience, but also an important link in optimizing the association between pages and helping SEO.However, when a user visits the first piece of content on a website, or the latest content in a category, the 'previous' document naturally does not exist.At this time, if the template is not handled properly, it may cause blank areas on the page, style disorders, and even leave a bad user experience

2025-11-07

How to get the release (CreatedTime) or update time (UpdatedTime) of the previous document using the `prevArchive` tag?

## The clever use of `prevArchive` tag: Deeply explore the time mystery of the previous document in AnQi CMS As a senior website operation expert, I know that the timeliness and update frequency of content are crucial for the SEO performance and user experience of the website.In AnQiCMS (AnQiCMS), we often need to provide "Previous" and "Next" navigation on the article detail page, which is not only convenient for users to browse but also a good method to build internal links and improve page authority.Today, let's delve into the `prevArchive` tag

2025-11-07

Can you get the views (Views) information of the previous document through the `prevArchive` tag?

## Deep Dive into AnQi CMS: Can the `prevArchive` tag retrieve the page views of the previous document?As an expert in website operations for many years, I know that every CMS system is crucial in terms of content management and data presentation.AnQiCMS (AnQiCMS) boasts its high efficiency and flexibility, and has been favored by many small and medium-sized enterprises and content operators.

2025-11-07

`prevArchive` label outside the article detail page (such as the list page) whether it can still effectively obtain the previous document?

## Deep Dive into the `prevArchive` tag of Anqi CMS: The Mystery of the 'Previous' on List Pages As an experienced website operations expert, I am well aware that in daily content management, every tag and every function contains the potential to improve user experience and operational efficiency.AnQiCMS, with its simple and efficient features and SEO-friendly characteristics, has become a powerful assistant for many small and medium-sized enterprises and self-media operators.

2025-11-07

How to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag?

As an experienced website operations expert, I am well aware of the importance of meticulous template customization in content management systems for enhancing user experience and the overall style of the website.AnQiCMS (AnQiCMS) provides us with great flexibility with its efficient architecture based on the Go language and a Django-like template engine.Today, let's delve into a common customization requirement: how to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag for the 'previous article'.

2025-11-07