How to display the links and titles of the previous and next related articles on the document detail page of Anqi CMS?

Calendar 👁️ 72

In AnQi CMS, adding links and titles for "Previous Article" and "Next Article" on the document detail page is a very practical feature to enhance user experience and content consistency.This not only encourages users to browse more content, but also helps optimize the internal links of the website.AnQi CMS provides simple and efficient template tags, allowing us to easily meet this requirement.

Understanding the template mechanism of Anqi CMS

The template system of AnQi CMS is designed to be very intuitive, it adopts syntax similar to the Django template engine.This means you can output variables and call function tags with specific symbols.Generally, we need to use double curly braces in template files{{ 变量名 }}To display data, the function tag is represented by single curly braces and the percent sign.{% 标签名 参数 %}To invoke, and with.{% end标签名 %}This structure makes the template code easy to understand and maintain.

When you browse to the detail page of a document, the environment of Anqi CMS has automatically loaded the relevant information of the current document.Therefore, to obtain the "previous" and "next" articles, we do not need to pass the ID of the current document, the system will automatically identify and match.

Implement the 'Previous' document link and title

To display the 'Previous' article of the current document, we can use the built-in functions of Anqi CMSprevArchiveLabel. This label will intelligently search for articles published before the current document and provide their details.

How to use the label:

{% prevArchive prev %}
  {# 在这里,'prev' 是您为上一篇文章数据定义的变量名 #}
  {# 您可以使用 'prev.Link' 获取链接,'prev.Title' 获取标题 #}
{% endprevArchive %}

Code example:

On your document detail page (usually)archiveunder the modeldetail.htmlOr a custom detail page template) you can add code to display the previous article:

<div class="article-pagination">
  <div class="prev-article">
    {% prevArchive prev %}
      {% if prev %}
        <a href="{{ prev.Link }}" title="{{ prev.Title }}">
          <span class="pagination-label">上一篇:</span>
          <span class="pagination-title">{{ prev.Title }}</span>
        </a>
      {% else %}
        <span class="pagination-label">上一篇:</span>
        <span class="pagination-title">没有了</span>
      {% endif %}
    {% endprevArchive %}
  </div>
  {# 这里将放置下一篇文章的代码 #}
</div>

In this example, we first{% prevArchive prev %}Define a variable namedprevvariable to receive the data of the previous article. Then, use{% if prev %}Determine if the previous article exists. If it does, build a link that includes it{{ prev.Link }}and the title{{ prev.Title }}of<a>Label; if not exists, then display "None", which can well handle boundary cases and improve user experience.

Implement "Next article" document link and title

Similar to the 'Previous article', AnQi CMS providesnextArchivetags to get the 'Next article' of the current document.

How to use the label:

{% nextArchive next %}
  {# 在这里,'next' 是您为下一篇文章数据定义的变量名 #}
  {# 您可以使用 'next.Link' 获取链接,'next.Title' 获取标题 #}
{% endnextArchive %}

Code example:

Following the code of the 'Previous article' above, you can use the samediv.article-paginationAdd the display of the next article in the structure:

<div class="article-pagination">
  {# 上一篇文章的代码,如上所示 #}
  <div class="prev-article">
    {% prevArchive prev %}
      {% if prev %}
        <a href="{{ prev.Link }}" title="{{ prev.Title }}">
          <span class="pagination-label">上一篇:</span>
          <span class="pagination-title">{{ prev.Title }}</span>
        </a>
      {% else %}
        <span class="pagination-label">上一篇:</span>
        <span class="pagination-title">没有了</span>
      {% endif %}
    {% endprevArchive %}
  </div>

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

By such a layout, users can clearly see and click to go to related previous and next articles after reading the current article, forming a smooth reading path.

Integration and Practice Notes

  1. Template File Location: Add the above code snippet to your document detail page template. According to the Anqi CMS convention, this is usuallytemplate/您的模板目录/{模型table}/detail.htmlOr you can customize the template file for a specific document in the background.
  2. CSS styleTo make the 'Previous' and 'Next' link look more beautiful, you can add the corresponding CSS style according to your website designdiv.article-pagination/div.prev-article/div.next-articleas well as the display of its internal elements.
  3. encoding issues: Please ensure that your template file uses UTF-8 encoding consistently to avoid garbled display of Chinese titles and other content.
  4. case sensitivity of tagsThe template tags of AnQi CMS are strictly case-sensitive, for exampleprevArchiveandPrevArchiveare different, please make sure to keep them consistent.

By following these simple steps, you can effectively display the links and titles of the 'previous' and 'next' articles on the document detail page of AnQi CMS, thereby optimizing the user experience and enhancing the interactivity of the website content.


Frequently Asked Questions (FAQ)

1. Why is the previous/next link not displayed on my document detail page?There may be several reasons. First, please check if the template file has been added correctly.prevArchiveandnextArchiveLabel, and spelled correctly. Secondly, ensure that the current document indeed exists a previous or next article that can be linked (for example, if it is the first article published, there is no previous one).Additionally, these tags usually only have valid output on the document detail page (i.e., the page that displays the content of a single article), and may not have results on other pages (such as list pages).

2. I want the previous/next link to display not only the title but also a thumbnail or the publication date, can it be done?Of course you can.prevArchiveandnextArchivethe tags returned byprevandnextThe variable contains various information about the article, such asThumb(thumbnail),CreatedTime(Publish time) and so on. You can call these fields in the same way as you get the title, and format them appropriately in the template. If you need to format the timestamp, you can use{{ prev.Thumb }}or{{ next.CreatedTime }}to call these fields and format them appropriately in the template. If you need to format the timestamp, you can use{{ stampToDate(prev.CreatedTime, "2006-01-02") }}such tags.

3. What is the order in which the 'Previous Article' and 'Next Article' are sorted?Of Security CMSprevArchiveandnextArchiveThe tag is usually determined by the publication time of the article (or the internal ID).They usually look for the previous or next article closest in time and in the same category as the current article.This means that if the order of your article's publication changes, the links to the previous/next articles will also be adjusted accordingly.

Related articles

How to use the `archiveFilters` tag to add advanced filtering functionality to the document list of AnQi CMS?

Manage content in Anqi CMS, especially when the website content becomes rich, how to help visitors quickly find the information they need has become the key to improving user experience.If your website offers a diverse range of products or services, or contains a large number of articles with different attributes, then an efficient filtering function will be essential.Today, let's delve into a very useful tag in Anqi CMS, `archiveFilters`, which helps us easily add advanced filtering features to the document list.The foundation of the flexible content model

2025-11-07

How to use the `archiveList` tag to flexibly build various document lists and pagination display in Anqi CMS?

Manage and display content is a core operation in Anqi CMS, where the `archiveList` tag plays a crucial role.It can not only help us flexibly present lists of various documents such as articles, products, etc., but also seamlessly connect with the pagination function, meeting various complex content display needs.## Getting to Know the `archiveList` Tag: A Tool for Displaying Content The `archiveList` tag is a core tool in the Anqi CMS template used to retrieve document lists.

2025-11-07

How to display detailed information of a specific document in the Anqi CMS template, including the title, content, and thumbnail?

In AnQi CMS, sometimes we may need to display detailed information of a preset document at a specific location on the website, such as a recommendation area on the homepage or the '精选内容' module in the sidebar, including its title, content, and an eye-catching thumbnail.To achieve this goal, Anqi CMS provides a very flexible and intuitive way.

2025-11-07

How to create and store a mobile template in Anqi CMS to ensure the normal display of a mobile website?

Build and manage mobile templates in AnQiCMS to ensure your website displays correctly on mobile devices, you need to understand its flexible template adaptation mechanism and clear file storage rules.AnQiCMS provides various mobile adaptation modes, allowing you to choose the most suitable method according to your actual needs. ### Understanding AnQiCMS' Mobile Adaptation Mode Firstly, we need to understand the three main mobile adaptation modes supported by AnQiCMS: 1.

2025-11-07

How to quickly judge whether a string of text in the AnQiCMS template contains specific sensitive words?

In website content operation, compliance and security are of great importance.Especially for platforms with user-generated content (UGC) or when publishing articles, product information, we often need to quickly determine if a string of text contains specific sensitive words.AnQiCMS is an efficient enterprise-level content management system that also provides very flexible and convenient tools at the template level, allowing you to easily meet this requirement.

2025-11-07

How to use the `contain` filter to check if the user's input text contains the preset brand name?

In daily website content operations, we often need to standardize the management of user input or content generated by the system, especially when it involves brand names.Maintaining the consistency and accuracy of the brand name is crucial, not only for enhancing the brand image, but also for the SEO performance of the website, legal compliance, and user experience.AnQi CMS provides a flexible and powerful template engine, where the `contain` filter is a very practical tool that can help us efficiently check if the text contains the preset brand name.Why check the brand name in the content

2025-11-07

How to determine if a specific value exists in an array (slice) while developing an AnQi CMS template?

During the development of Anqi CMS templates, we often encounter scenarios where we need to determine whether an array (slice) contains a specific value.For example, you may need to dynamically adjust the display of content based on whether the user tag exists in a predefined tag list;Or when handling complex business logic, determine whether a permission ID exists in the current user's permission set.For this requirement, AnQiCMS template engine provides a concise and powerful solution, allowing developers to handle these logic in an elegant way.In the AnQiCMS template system

2025-11-07

Can `contain` filter be used in AnQiCMS template to check if a key exists in a map or struct?

In Anqi CMS template development, flexible handling of data structures is the key to dynamic content display.When we need to determine whether a complex data type, such as a key-value pair (map) or a structure (struct), contains a specific key name, the built-in `contain` filter provides a convenient and efficient solution.

2025-11-07