How to get the title, link, and thumbnail of the previous and next articles of the current article?

Calendar 👁️ 55

As a website manager who deeply understands the operation of Anqing CMS, I am well aware of the importance of the details of content presentation for user experience and the overall performance of the website.The navigation function on the article detail page can not only effectively guide users to continue browsing and reduce the bounce rate, but also is an effective means to enhance the correlation between pages and optimize the internal link structure.AnQi CMS provides a concise and efficient template tag, allowing us to easily implement this function.


Improve content coherence: Implementing previous and next article navigation in AnQiCMS

In website content operation, the 'Previous' and 'Next' navigation function on the article detail page is a key element to enhance user experience and guide users to in-depth browsing.It can not only help readers seamlessly jump from the current article to related content, but also effectively enhance the internal link structure of the website, and is also very beneficial for search engine optimization (SEO).AnQiCMS (AnQiCMS) provides intuitive and powerful template tags, allowing website operators to easily implement this feature and flexibly control the displayed content.

Understanding the previous and next article navigation mechanism in AnQiCMS

AnQiCMS's template system adopts the syntax of Django template engine, providing special tags to obtain the previous and next articles of the current article:prevArchiveandnextArchiveThese tags work automatically in the context of the article detail page, and there is no need for complex parameter configuration to obtain data from adjacent articles.The object returned includes the title, link, thumbnail, and other common information that can be directly called in the template.

Get information about the previous article

To display the title, link, and thumbnail of the previous article on the current article page, we can useprevArchiveThe tag returns an object representing the article that is ranked before the current article according to the system's default sorting rules (usually publication time or ID).

We first use{% prevArchive prev %}Attempt to retrieve the data of the previous article and assign it to a variable namedprev. To ensure the robustness of the page rendering, we also need to judge thisprevDoes the variable exist, because not all articles have a previous one (such as the first article in a series).

InprevWhen the variable exists, we can safely access its properties:

  • {{ prev.Title }}Get the title of the previous article.
  • {{ prev.Link }}Get the link address of the previous article.
  • {{ prev.Thumb }}Get the thumbnail address of the previous article.

The following is an example of the template code to implement the navigation of the previous article:

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

In this code, we first try to obtainprevthe article object. IfprevThe object exists (i.e., there is a previous article), then render a thumbnail, title, and link<a>tag. If it does not exist, then display a prompt message.

Get information about the next article

Similarly, to get and display the navigation information of the next article, we usenextArchiveThe tag will return an object representing an article that follows the current article according to the system's default sorting rule.

We pass{% nextArchive next %}The statement retrieves the data of the next article and assigns it tonextVariable. Similarly, it also needs to be judged.nextDoes the variable exist?

InnextWhen the variable exists, we can access the following properties:

  • {{ next.Title }}: Get the title of the next article.
  • {{ next.Link }}Get the link address of the next article.
  • {{ next.Thumb }}Get the thumbnail address of the next article.

Here is an example of the template code to implement navigation to the next article.

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

This code logic is similar to the previous article, ensuring navigation is provided when there is a next article, otherwise a prompt is displayed.

Complete example with **practice

In the actual website article detail page, we usually place the navigation for the previous and next articles side by side to provide a continuous reading experience.

A typical article detail page footer navigation structure may look like this:

<article class="article-detail-content">
  <!-- 这里是当前文章的内容 -->
</article>

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

  {% nextArchive next %}
  <div class="nav-item next-article">
    {% if next %}
      <a href="{{ next.Link }}" title="下一篇:{{ next.Title }}">
        <img src="{{ next.Thumb }}" alt="下一篇:{{ next.Title }}" class="thumb">
        <span class="label">下一篇</span>
        <span class="title">{{ next.Title }}</span>
      </a>
    {% else %}
      <span class="placeholder">没有下一篇文章了</span>
    {% endif %}
  </div>
  {% endnextArchive %}
</nav>

During the implementation process, it is recommended to place these code snippets in the template file of the article detail page (for example{模型table}/detail.htmlMeanwhile, using CSS to style these navigation elements, making them consistent with the overall visual style of the website, thus providing users with a better reading experience.By reasonably using these tags, we can significantly improve the fluidity and user engagement of the website content.


Frequently Asked Questions (FAQ)

1.prevArchiveandnextArchiveHow to determine the 'previous' and 'next' articles of an article?

Of Security CMSprevArchiveandnextArchiveTags are usually based on the publication time of the article (CreatedTimeOr sort by article ID to determine the nearest articles. They will automatically search in the context of the current article, such as in the same category or throughout the site.These tags do not accept additional sorting parameters and therefore follow the default system sorting logic or that determined by the content model.

2. Can I also get other information about the previous/next article besides the title, link, and thumbnail?

Of course you can.prevArchiveandnextArchiveThe object returned by the tag witharchiveDetailThe label returns an object structure similar, so you can access almost all fields of the article. For example, you can through{{ prev.Description }}Get the summary of the previous article through{{ next.Views }}Get the next article's view count. You can check the AnQiCMS template tag document for more information.archiveDetailList of all available fields, these fields are also applicable toprevandnextObject.

3. If the article does not have a thumbnail,{{ prev.Thumb }}what will be displayed?

If the article does not have a thumbnail set explicitly,{{ prev.Thumb }}(or{{ next.Thumb }}It will usually return an empty string. To avoid broken image icons on the page, you can use conditional judgment in the template, for example:

{% if prev.Thumb %}
  <img src="{{ prev.Thumb }}" alt="上一篇:{{ prev.Title }}" class="thumb">
{% else %}
  <img src="/static/images/default-thumb.png" alt="无图" class="thumb"> {# 显示默认缩略图 #}
{% endif %}

Or, you can also configure the default thumbnail in the AnQiCMS backend "Content Settings".This way, when the article does not have a specific thumbnail, the system will automatically use the default image you uploaded.

Related articles

How to implement complete pagination functionality for the article list in AnQiCMS template?

As an expert deeply familiar with the operation of AnQiCMS, I know that a smooth, user-friendly website experience is crucial for attracting and retaining users.The pagination feature of a content list is the cornerstone of any content-intensive website, not only optimizing the user's browsing experience, but also an important aspect of search engine optimization.In AnQiCMS, achieving complete pagination for the article list is efficient and flexible through its powerful template tag system.

2025-11-06

How to use the `archiveList` tag to get the article list and support sorting by ID, views, or custom sorting?

As an experienced CMS website operation person, I know that efficient content management is crucial for attracting and retaining users.The template tag system provided by AnQi CMS is its strong point, among which the `archiveList` tag is the core of daily content display.It can help us flexibly extract articles, products, and other content from the database and sort and display them in the way we want.

2025-11-06

How to get the list of all single pages or the detailed content of a specific single page in AnQiCMS template?

As a senior security CMS website operator, I am well aware of the importance of high-quality, well-structured content for website user experience and search engine optimization.A single page is the core of a website's basic information display, such as "About Us", "Contact Information", and "Terms of Service", etc.In AnQiCMS, through the powerful template tag system, we can flexibly obtain and display the content of these single pages. I will elaborate in detail on how to obtain the list of all single pages and the detailed content of a specific single page in the AnQiCMS template.###

2025-11-06

How to get the details of the current access category, including the title, link, description, and custom fields?

As an experienced CMS website operator, I am well aware of the importance of high-quality and easily accessible content information for website user experience and search engine optimization.In Anqi CMS, obtaining detailed information about the current visited category is a very basic and frequent requirement in website construction. Whether it is used for page titles, navigation breadcrumbs, or detailed introductions on category pages, it is necessary to accurately call these data.Our AnQi CMS provides a powerful and flexible template tag system, making it extremely easy to obtain the title, link, description, and even custom fields of the current visited category

2025-11-06

How to display a list of recommended articles related to the current article content, supporting keyword search or manual association?

As an experienced CMS website operation person in the security industry, I know that high-quality content and accurate recommendations are important for improving user experience and website SEO.In the article detail page, effectively displaying recommended articles related to the current content can not only extend the user's visit time and reduce the bounce rate, but also optimize and improve the page weight and crawling efficiency through internal links.AnQi CMS provides flexible tags, supporting us to build this recommendation list through keywords or manual methods.### Implementing related article recommendations in AnQi CMS AnQi CMS uses a powerful template tag system

2025-11-06

How to retrieve and display the custom parameter field value of the article through template tags in AnQiCMS?

In AnQiCMS (AnQiCMS), the custom parameter field provides great flexibility and scalability for website content.As a website operator familiar with AnQi CMS, I am well aware of how to effectively utilize these fields and display them on the website front end to meet diverse content display needs.This article will elaborate on how to use the AnQi CMS template tags to obtain and display the custom parameter field values of the article.### Understanding the customized parameter fields of AnQi CMS AnQi CMS allows users to customize the content model according to business needs

2025-11-06

How to build a list page of articles with filtering conditions, such as filtering by custom properties?

As an experienced CMS website operation personnel of an enterprise, I know how to meet user needs through refined content presentation.Build a list page of articles with filtering conditions, especially on custom attributes, is an important means to enhance user experience and help users quickly find the information they need.AnQi CMS, with its flexible content model and powerful template tags, makes this process efficient and intuitive.Build a list page of articles filtered by custom attributes, mainly involving the following core stages: first, define and configure these custom attributes in the background management system; next,

2025-11-06

How to display the Tag list of articles in AnQiCMS template and generate links for each Tag?

The generation and display of article Tag list and its links in AnQiCMS template As a website operator who deeply understands the operation of AnQiCMS and has a profound understanding of content operation, I know that article tags (Tags) play a core role in improving content discoverability, optimizing user experience, and strengthening website SEO.Tags can not only help readers find related content quickly, but also provide more rich semantic information for search engines.This article will detail how to efficiently display the tag list in AnQiCMS templates

2025-11-06