How to display the link and title of the previous and next article in AnQiCMS template?

Calendar 👁️ 65

In website operation, it is crucial to provide visitors with a smooth navigation experience.When a user finishes reading an article, they naturally expect to find more related content, and the 'Previous' and 'Next' links are the key features that meet this need.They can not only improve the user's stay time on your website, but also have a positive impact on search engine optimization (SEO) by building internal link structure.

AnQiCMS provides concise and efficient built-in tags for template developers, allowing you to easily display links and titles of the previous and next articles on the article detail page.Below, we will together learn how to implement this feature in the AnQiCMS template.

Understand core tags:prevArchiveandnextArchive

AnQiCMS provides two special tags for retrieving adjacent article information:

  • prevArchive: Used to retrieve information about the 'previous' article of the current article.
  • nextArchiveUsed to get the information of the next article of the current article.

These tags work intelligently in the context of the article detail page, automatically determining the current article's ID and category, and finding adjacent articles in the same category.

Basic Usage: Display Links and Titles

The most common requirement is to display the title and corresponding link of the previous and next articles. You can add the following code snippet to the template below the content area or above the comment area on the article detail page:

<nav class="article-navigation">
    <div class="prev-article">
        {# 获取上一篇文章信息,并将其赋值给变量 'prev' #}
        {% prevArchive prev %}
            {# 检查是否存在上一篇文章 #}
            {% if prev %}
                <span>上一篇:</span>
                <a href="{{ prev.Link }}" title="{{ prev.Title }}">{{ prev.Title }}</a>
            {% else %}
                {# 如果没有上一篇文章,则显示提示信息 #}
                <span>上一篇:没有了</span>
            {% endif %}
        {% endprevArchive %}
    </div>
    <div class="next-article">
        {# 获取下一篇文章信息,并将其赋值给变量 'next' #}
        {% nextArchive next %}
            {# 检查是否存在下一篇文章 #}
            {% if next %}
                <span>下一篇:</span>
                <a href="{{ next.Link }}" title="{{ next.Title }}">{{ next.Title }}</a>
            {% else %}
                {# 如果没有下一篇文章,则显示提示信息 #}
                <span>下一篇:没有了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</nav>

Code analysis:

  • {% prevArchive prev %}This tag attempts to retrieve the previous article of the current article, if found, it will store all its information in a namedprev.{% endprevArchive %}This is the end tag.
  • {% if prev %}: This is a conditional judgment, used to check.prevWhether the variable successfully retrieves the content (i.e., whether the previous article exists). If it exists, then executeifThe code within the block.
  • {{ prev.Link }}: fromprevRetrieve the link address of the previous article in the variable.
  • {{ prev.Title }}: fromprevRetrieve the title of the previous article in the variable.
  • {% else %}If:prevIf the variable is empty (i.e., there is no previous article), then executeelseThe code inside the block displays the prompt 'Nothing here'.
  • nextArchiveThe way of using tags andprevArchiveExactly the same, but it retrieves the information of the next article and stores it in.nextthe variable.

Advanced usage: Add more information

In addition to the title and link, you may also want to display more details of the articles in the navigation, such as thumbnails (Thumb), description (Description) etc., to provide a richer preview.prevandnextThe variable contains various fields in the article, you can call it as needed.

Here is an example of adding a thumbnail to the navigation.

<nav class="article-pagination">
    <div class="pagination-item prev-item">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{ prev.Link }}" title="{{ prev.Title }}" class="pagination-link">
                    {% if prev.Thumb %}
                        <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="pagination-thumb">
                    {% endif %}
                    <span class="pagination-text">上一篇:{{ prev.Title }}</span>
                </a>
            {% else %}
                <span class="pagination-text no-more">上一篇:没有了</span>
            {% endif %}
        {% endprevArchive %}
    </div>
    <div class="pagination-item next-item">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }}" class="pagination-link">
                    <span class="pagination-text">下一篇:{{ next.Title }}</span>
                    {% if next.Thumb %}
                        <img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="pagination-thumb">
                    {% endif %}
                </a>
            {% else %}
                <span class="pagination-text no-more">下一篇:没有了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</nav>

In this example, we added{% if prev.Thumb %}Determine whether the previous article has a thumbnail and display it. This provides users with a more intuitive navigation cue.

How to apply the code to your template

  1. Confirm the template file:Generally, the template file of the article detail page is locatedtemplate/{您的模板目录}/{模型table}/detail.html. For example, if it is an article model, it may betemplate/default/article/detail.html. You can find and edit the corresponding template file online through the "Template Design" -> "Website Template Management" feature in the AnQiCMS backend.

  2. Select a suitable location:Indetail.htmlIn the file, find the position where you want to display the previous/next link. This is usually after the article content,divbut before the comments section or related article list.

  3. Paste and adjust the code:Paste the above code snippet into the selected location. You can adjust it according to the actual design of your website.divLabel the class and add the corresponding CSS styles to maintain consistency with your website.

  4. Save and preview:Save the template file and then visit any article detail page on the website, check if the links to the previous and next articles are displayed correctly.

Important reminder and **practice

  • Automatically judge the context: prevArchiveandnextArchiveThe power of tags lies in the fact that they do not require you to manually pass the current article ID or other parameters; they automatically recognize the context of the article on the current page.
  • Gracefully handle the case of no content:Always use{% if %}The statement to determine if the previous or next article exists. This can prevent errors or blank links from appearing on the page when there are no adjacent articles.
  • Improve user experience:A good previous/next navigation can guide users to explore your website content deeply, reducing the bounce rate.
  • Optimize internal links:These navigation links create natural internal links for your website, which helps search engines better crawl and understand your website structure, thereby improving SEO effectiveness.

By utilizing the AnQiCMS providedprevArchiveandnextArchiveLabel, you can easily add a powerful and user-friendly navigation feature to the article detail page of your website, thereby optimizing the user experience and enhancing the overall performance of the website.


Frequently Asked Questions (FAQ)

Question 1: Why is the previous/next article link not displayed on the page even though I added code in the template? Answer:There may be several reasons. First, make sure the article you are viewing does have a previous or next article (i.e., it is not the first or last in the category).Next, check if you have correctly pasted the code into the template file of the article details page (for exampledetail.htmlIn it, and there are no spelling errors. Finally, if your AnQiCMS has enabled caching, please try to clear the website cache in the background and then visit the page again.

Question 2: Can these tags be used on the article list page or the homepage? Answer:No.prevArchiveandnextArchiveTags are specifically designed for

Related articles

How to implement filtering in the article list based on custom parameters (such as product features, price range)?

In website operation, we often need to classify and filter content lists more finely to help users quickly find the information they are really interested in.Traditional article classification can solve most problems, but when the content attributes become more complex, such as products with multiple characteristics, price ranges, or events with different themes and participation methods, a single classification seems to be inadequate.

2025-11-08

How to implement a search function on the front end of a website and display a list of search results with highlighted keywords?

When building a rich website, providing an efficient and convenient search function is a key aspect of improving user experience.AnQiCMS (AnQiCMS) has fully considered this from the beginning of its design, through its flexible template engine and built-in tags, we can relatively easily implement search functionality on the website front-end, and further optimize it to make the keywords in the search results stand out and highlight prominently.### Core Mechanism: Understanding the Search Principle of AnQiCMS The core of AnQiCMS website frontend search lies in `search/index.html`

2025-11-08

How to implement content pagination display and customize page navigation style in AnQiCMS template?

As the content of the website becomes richer, how to efficiently display a large amount of information while ensuring a user-friendly browsing experience is an indispensable link in website operation.In AnQiCMS, through the powerful template tag system, we can easily achieve content pagination display and flexibly customize the style of page navigation, making the website content both rich and tidy.--- ### Efficient Content Organization: Implementing Pagination of Content Lists In the AnQiCMS template, the core of implementing content pagination is to use the `archiveList` tag to retrieve document lists

2025-11-08

How to display the article list according to different sorting rules (such as latest, views, custom sorting)?

Managing website content in Anqi CMS, flexibly controlling the display order of article lists is crucial for improving user experience and content distribution efficiency.Whether you want to immediately display the latest released content to visitors, highlight the most popular hot articles, or manually adjust the arrangement of articles according to specific operational strategies, Anqi CMS provides a simple and powerful way to meet these needs.One of the core advantages of AnQi CMS is its intuitive and feature-rich template tag system.

2025-11-08

How to display a list of related documents on the document detail page, such as categorized recommendations or keyword-based recommendations?

In website content operation, providing more relevant and potentially interesting content to visitors is a key strategy to enhance user experience, extend website stay time, and promote in-depth content browsing.This not only effectively guides users to explore more information, but is also an important component of 'inter-page relevance' in Search Engine Optimization (SEO).In such a powerful content management system as AnQiCMS, it is easy and efficient to implement the display of related document lists on the document detail page.

2025-11-08

How to perform simple arithmetic operations such as addition, subtraction, multiplication, and division in AnQiCMS templates?

When creating templates in AnQiCMS, we often need to perform some simple numerical calculations, such as displaying the total price of goods, calculating the percentage of article reading volume, or handling the serial numbers in the list.AnQiCMS is a powerful template engine that supports direct arithmetic operations such as addition, subtraction, multiplication, and division in templates, making our content display more flexible and dynamic.

2025-11-08

How to use the filter (filter) to truncate, convert case, or escape HTML in displayed text?

When building a website, we often need to process various text content displayed on the page, such as limiting the length of article abstracts, unifying the case format of user input, or ensuring that user submitted content can be safely displayed on the page without destroying the page structure.AnQiCMS (AnQiCMS) provides us with powerful template filter functions, which can efficiently and conveniently complete these tasks.The filter is a very practical tool in the Anqi CMS template, which helps us quickly process and format the data displayed on the page.

2025-11-08

How to display a preset default value (such as "No data") for empty variables in the template?

In website operation, the completeness of content display and user experience is crucial.When we call data in AnQiCMS (AnQiCMS) template, we sometimes encounter the situation where some variables are empty.If these empty variables are not processed, the front-end page may appear blank areas, 'null' text, and even cause layout disorder, thus affecting the professionalism of the website and the user's browsing experience.

2025-11-08