How to display links to the previous and next articles on the AnQiCMS article detail page?

Calendar 👁️ 82

When visitors browse articles on a website, they often hope to be able to jump to related content conveniently, especially the previous or next one.This design not only improves the user experience, but also has a positive impact on the internal link structure of the website and search engine optimization.AnQiCMS has fully considered this user's needs, built simple and efficient template tags, and helped us easily implement the function of linking to the previous and next articles on the article detail page.

Display links to the previous and next articles on the AnQiCMS article detail page

In AnQiCMS, displaying the link to the previous and next articles mainly depends on two core template tags:prevArchiveandnextArchiveThese tags will automatically find and return adjacent article information based on the publication time of the current article.

To implement this feature, we need to edit the template file of the article detail page. According to the template conventions of AnQiCMS, the template file for the article detail page is usually located in your template directory.{模型table}/detail.htmlFor example, if it is an article model, it is usuallyarticle/detail.html.

When editing the template file, you can add the following code snippet to the location where you want to display the links to the previous and next articles, such as at the bottom or sidebar of the article content.

Basic Usage Example (Only Display Title):

First, let's see how to simply display the link and title of the previous article:

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}">&laquo; {{ prev.Title }}</a>
        {% else %}
            <span>&laquo; 没有了</span>
        {% endif %}
        {% endprevArchive %}
    </div>
</div>

In this code,{% prevArchive prev %}The tag attempts to retrieve the information of the previous article of the current article and stores it inprevthe variable. We use{% if prev %}to determine if the previous article exists. If it does, then through{{ prev.Link }}Retrieve article link through{{ prev.Title }}Get the article title and display it as a clickable link.If there is no previous article (for example, the current article is the first in a series), then display the prompt 'none'.

Similarly, the link and title of the next article can be usednextArchivetags to implement:

<div class="article-navigation">
    <div class="next-article">
        {% nextArchive next %}
        {% if next %}
            <a href="{{ next.Link }}">{{ next.Title }} &raquo;</a>
        {% else %}
            <span>没有了 &raquo;</span>
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

here,{% nextArchive next %}The tag will store the information of the next article innextthe variable, with the logic ofprevArchivebeing exactly the same.

Enhanced usage example (including thumbnails and full layout):

To provide a richer navigation experience, we usually combine the display of article titles and thumbnails. Here is a complete example of linking the previous and next articles side by side, including a thumbnail:

<div class="article-pagination-wrapper">
    <div class="prev-article-link">
        {% prevArchive prev %}
        {% if prev %}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                {% if prev.Thumb %}<img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" />{% endif %}
                <span>&laquo; {{ prev.Title }}</span>
            </a>
        {% else %}
            <span class="no-article-link">&laquo; 没有了</span>
        {% endif %}
        {% endprevArchive %}
    </div>
    <div class="next-article-link">
        {% nextArchive next %}
        {% if next %}
            <a href="{{ next.Link }}" title="{{ next.Title }}">
                <span>{{ next.Title }} &raquo;</span>
                {% if next.Thumb %}<img src="{{ next.Thumb }}" alt="{{ next.Title }}" />{% endif %}
            </a>
        {% else %}
            <span class="no-article-link">没有了 &raquo;</span>
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

In this enhanced example:

  • We usedivThe element wraps the links to the previous and next posts and adds respectively:prev-article-linkandnext-article-linkClass names, which are convenient for subsequent CSS styling and achieve left-right layouts, etc.
  • {% if prev.Thumb %}and{% if next.Thumb %}Check if the article has a thumbnail.ThumbThe field will return the URL of the thumbnail.
  • altThe attribute is set to the article title, which is very important for image SEO and accessibility.
  • titleThe attribute has added a mouse hover tip to the link.

Please note the code in the abovearticle-pagination-wrapper/prev-article-link/next-article-linkandno-article-linkThese are sample CSS class names, you can modify or replace them according to your website design needs, and write the corresponding CSS styles.

Important reminder and **practice

  • Location of the template file: Make sure you are editing the correct article detail page template. Typically, its naming will be related to the content model, for examplearticle/detail.htmlorproduct/detail.html.
  • Conditional judgment:Always use{% if prev %}or{% if next %}Make a judgment because not all articles have a previous or next article.For example, the article with the earliest publication time does not have a previous one, and the article with the latest publication time does not have a next one.This can prevent invalid empty links from appearing on the page.
  • Automatically obtain context: prevArchiveandnextArchiveThe tag on the article detail page will automatically retrieve the context information of the current article, usually you do not need to pass it manuallyidorcategoryIdsuch parameters, which will intelligently find the adjacent articles.
  • Style control:The template code is responsible for outputting the HTML structure and content, while the layout, color, font, and other visual presentations of the links need to be controlled through CSS stylesheets. You can add the following code in yourdivandaAdd custom class names to tags and then define styles in your CSS file.
  • SEO friendly:The link to the previous and next article is a good internal link practice, which helps search engine spiders crawl more pages of the website, pass on page authority, and thus improve the overall SEO performance of the website.

Provided by AnQiCMSprevArchiveandnextArchiveLabel, we can flexibly and efficiently add previous and next article navigation to the article detail page, which not only optimizes the user experience but also plays a positive role in the overall structure of the website and search engine optimization.


Frequently Asked Questions (FAQ)

  1. Why did I add the code but the previous/next article link is not displayed on the page?First, please check if your template file has been saved and activated.Next, make sure that the current article indeed has a logical 'previous' or 'next'.For example, if your website only has one article, or you are viewing the first article you published, then there is no previous one;On the contrary, if you are looking at the last article you have published, then there is no next one.In addition, please confirm that your article is in a normal published state on the AnQiCMS backend, and not in a draft or recycling bin.

  2. If I want to display only the article title in the link without the thumbnail, how should I adjust?If you do not want to display thumbnails, just remove all the parts included in the sample code{% if prev.Thumb %}...{% endif %}or{% if next.Thumb %}...{% endif %}Keep it<span>{{ prev.Title }}</span>or<span>{{ next.Title }}</span>Just do it.

  3. What determines the order of these previous/next articles?The previous and next article links in AnQiCMS are based on the publication time order (by default, it is sorted according to theCreatedTimeThe field is automatically determined. The system will find the nearest article before the current article's publication time as the previous article, and the nearest article after the publication time as the next article.

Related articles

How to display website logo and copyright information in AnQiCMS template?

When building and operating a website, the website's logo and copyright information are an important component of brand image, building user trust, and fulfilling legal statements.For AnQiCMS users, managing and displaying this information is very intuitive and flexible. ### In AnQiCMS backend, set the website logo and copyright information AnQiCMS centralizes the global configuration of the website, allowing you to easily set various basic information.To set the website logo and copyright, you need to go to the 'Global Function Settings' page in the backend.1.

2025-11-08

How to set the TDK (Title, Description, Keywords) of the AnQiCMS homepage to affect search results display?

In website operation, making your website stand out in search engines is a key step to gain traffic.While the "front door" of a website - the homepage, its display effect in search results is often determined by TDK (Title, Description, Keywords).AnQiCMS is a system focused on enterprise-level content management, which provides intuitive and powerful settings to easily control the homepage's image in the eyes of search engines.--- ### What is TDK and why is it so important

2025-11-08

How to get and display the list of articles under a specified category in AnQiCMS?

To retrieve and display a list of articles under a specified category in AnQiCMS is a very common requirement in website content operation.No matter if you want to display the latest articles of a specific category on the homepage or aggregate all the content of a special topic on an independent page, AnQiCMS's powerful template tag system can help you easily achieve it.AnQiCMS's template engine syntax is similar to Django, allowing you to directly call backend data in HTML templates using concise and clear tags and variables.This article will guide you on how to use `archiveList`

2025-11-08

How to implement pagination display of the article list in AnQiCMS?

In AnQiCMS, the pagination display of the article list is a very common and important function in content operation.It not only makes it easier for visitors to browse a large amount of content, improve user experience, but also has an indispensable role in search engine optimization (SEO), which can help search engines better crawl and index website content.AnQiCMS as an efficient and customizable content management system took this into full consideration from the beginning, therefore the pagination function of the article list is very intuitive and flexible.This is mainly due to its powerful template tag system

2025-11-08

How to display related article lists in AnQiCMS to enhance user browsing?

In content operations, guiding users to continuously explore within the site, extending their stay time, is one of the key strategies to improve user experience and website conversion rates.The list of relevant articles is an efficient tool to achieve this goal.AnQiCMS as a high-performance, flexible content management system provides various ways to cleverly display related articles, thereby deeply tapping into the browsing potential of users.Why is the related article list so important?

2025-11-08

How to enable Markdown editor and correctly render mathematical formulas and flowcharts in AnQiCMS?

Enable the complete guide to Markdown, rendering mathematical formulas and flowcharts in AnQiCMS AnQiCMS, as an efficient and flexible content management system, has been striving to provide more convenient and powerful content editing and display capabilities for content creators.For those who often need to write technical documents, academic papers, or explanations involving complex logic processes, the original rich text editor sometimes feels inadequate.

2025-11-08

How does AnQiCMS control the display of content in different areas through the 'Flag' attribute (such as recommended, headline)?

## AnQiCMS: How to make good use of the "Flag" attribute to accurately control the layout of website content In content operation, it is not enough to just publish articles.How to make important content stand out, how to intelligently display specific content in different areas of the website, is the key to improving user experience and operational efficiency.AnQiCMS is well-versed in this field and has provided us with a powerful and flexible tool - the 'Flag' attribute, to巧妙ly achieve this goal.What is the content "Flag" attribute?In short

2025-11-08

How to display the publication time of articles in the AnQiCMS template and customize the format?

In website content operation, the publication time of the article is a seemingly simple but crucial detail.It not only affects users' judgment of the timeliness of content, but is also an important reference factor for search engines to evaluate the freshness of content and for ranking.For AnQiCMS users, flexibly displaying and customizing the publication time of articles in templates is a basic operation to improve website user experience and SEO performance.

2025-11-08