Can the `prevArchive` tag retrieve the `Description` (abstract) field of the previous document?

Certainly, as an experienced website operations expert, I am more than happy to delve into the Anqi CMS.prevArchiveThe use of tags, and answer questions about obtaining the document summary (Description) field.


Unlock AnQi CMSprevArchiveTag: easily obtain the summary of the previous document

In the daily operation of websites, we often need to provide users with a smooth reading experience and guide them to discover more related content.This article details page's "Previous" and "Next" navigation plays a crucial role.AnQiCMS (AnQiCMS) is an efficient and flexible content management system, and naturally it also provides us with powerful template tags to easily achieve this function.prevArchiveLabel, and pay attention to whether it can obtain the previous document'sDescription(Abstract) field.

prevArchiveLabel: a powerful assistant for content navigation

prevArchiveThe label in the AnQi CMS template system, as the name implies, is used to obtain information about the "previous" document of the current document.It is usually applied to the document detail page, helping users to switch seamlessly from the content they are currently reading to the previous article in the series.

In the template design of AnQi CMS,prevArchiveThe use of the label is very intuitive, its basic form is:

{% prevArchive prev %}
    {# 在这里使用 prev 变量来访问上一篇文档的数据 #}
{% endprevArchive %}

Here,previs a custom variable name we define, it will carry all available data from the previous document. If the current document is the first in the category, thenprevThe variable will be empty, which requires us to make a judgment in the template to avoid displaying unnecessary links.

Core Answer:prevArchiveCan be obtainedDescriptionthe field?

The answer is:Absolutely!

According to the official document of Anqi CMS,prevArchiveCarried by the tagprevVariable, can access many core fields of the previous document, including the ones we are concerned aboutDescription(Abstract) field. This means that you can not only display the title and link of the previous document, but also add a brief abstract to it, which greatly enhances the attractiveness and information volume of navigation.

getDescriptionThe method of the field is very simple, just byprev.Descriptionas follows:

{% prevArchive prev %}
    {% if prev %}
        <div class="previous-article-summary">
            <h3>上一篇:<a href="{{ prev.Link }}">{{ prev.Title }}</a></h3>
            <p>{{ prev.Description }}</p> {# 这里就是获取上一篇文档的摘要 #}
        </div>
    {% else %}
        <p>这是当前分类下的第一篇文档,没有更早的内容了。</p>
    {% endif %}
{% endprevArchive %}

This way, when the user scrolls to the end of the document, they can not only see the title of 'Previous Article', but also catch a glimpse of its content summary, which has a significant positive effect on stimulating the user's click interest and improving the discovery rate of website content.

Enhance user experience: Combine more fields to create rich media navigation

Simply displaying the title and summary may not be enough.prevArchiveThe label supports obtaining many other useful fields, which you can cleverly combine to provide users with a richer and more intuitive navigation experience. In addition,TitleandDescription,You can also access the following fields:

  • Id: The unique ID of the document.
  • Link: The access link of the document.
  • Keywords: The keywords of the document.
  • CategoryIdThe ID of the category the document belongs to.
  • Views: Document views.
  • Logo: The cover image address of the document.
  • Thumb: Document cover thumbnail address.
  • CreatedTime: The creation time of the document (timestamp, needs to be formatted).
  • UpdatedTime: The update time of the document (timestamp, needs to be formatted).

For example, on your blog or news website, you can create a 'Previous' navigation block that includes a thumbnail, title, summary, and publish time:

{% prevArchive prev %}
    {% if prev %}
        <div class="prev-article-card">
            <div class="prev-article-thumb">
                {% if prev.Thumb %}
                    <a href="{{ prev.Link }}">
                        <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}">
                    </a>
                {% endif %}
            </div>
            <div class="prev-article-content">
                <p class="prev-article-meta">发布于:{{ stampToDate(prev.CreatedTime, "2006年01月02日") }}</p>
                <h4 class="prev-article-title">
                    <a href="{{ prev.Link }}">{{ prev.Title }}</a>
                </h4>
                <p class="prev-article-description">{{ prev.Description|truncatechars:100 }}</p> {# 摘要截断显示,避免过长 #}
            </div>
        </div>
    {% else %}
        <p class="no-prev-article">您正在阅读第一篇文档。</p>
    {% endif %}
{% endprevArchive %}

In the above code, we usedprev.Thumbto display the thumbnail,stampToDateThe filter to format time, and make use oftruncatecharsThe filter to ensure the summary will not be too long, thus maintaining the layout of the page.

Concluding remarks

Anqi CMS'sprevArchiveLabels not only can easily realize the navigation function of 'Previous document', but more importantly, they provide rich data interfaces, allowing website operators to deeply tap into the value of content, and enhance user experience and the attractiveness of website content through multiple information such as abstracts, thumbnails, etc.Flexibly use these tags, and your website will significantly improve user retention and in-depth content reading.


Common Questions (FAQ)

Q1:prevArchiveandnextArchiveWhat pages can the label be used on, and is there a need for special configuration?A1:prevArchiveandnextArchiveThe tag is mainly designed forDocument details page.In these pages, the system can automatically recognize the current document and find its logical previous or next page.In most cases, they do not require additional special configuration, as long as the current page is a document detail page, and there is a logical "previous" or "next" document, the tag will work normally and return data.archiveDetailLabel rendering or page URL structure not meeting expectations may lead to labels being unable to correctly obtain the context document.

Q2: If the previous document has not been filled inDescriptionfield,{{ prev.Description }}What will be displayed?A2: If the previous document'sDescriptionfield is not filled in on the back end,{{ prev.Description }}This will display an empty string when rendering on the front end, meaning no content will be output. This usually will not cause the page to report an error, but for a better user experience, you can combine conditional judgment processing, for example:

{% if prev.Description %}
    <p>{{ prev.Description }}</p>
{% else %}
    {# 可以在这里显示一段默认文本,或者不显示摘要区域 #}
    <p>点击查看上一篇精彩内容!</p>
{% endif %}

Q3: Besides obtainingTitleandDescription,prevArchiveWhat other fields can be obtained to enrich the display effect of the previous document?A3: BesidesTitleandDescription,prevArchiveTags also provide many useful fields, such as:

  • Link:Previous document's URL link.
  • Thumb:Previous document's thumbnail URL, which can be used to display a visual preview.
  • CreatedTime:Previous document's publication time, which can be accessed throughstampToDateFilter format display, providing time clues.
  • ViewsThe number of views of the previous document can be used as an indicator of the popularity of the content. Flexible use of these fields allows you to design a more attractive and user-friendly "Previous Article" navigation block.