How to display the link to the previous and next article on the Anqi CMS content page?

Calendar 👁️ 73

In Anqi CMS, to enhance the user experience of the website and the efficiency of internal links, it is a common requirement to add navigation links to the "Previous Article" and "Next Article" on the content page.These links not only help visitors browse related content more smoothly, but also have a positive impact on the website's SEO performance.AnQi CMS provides a set of intuitive template tags, allowing you to easily display these navigation functions on content detail pages.

Core feature: useprevArchiveandnextArchiveTag

Anqi CMS passedprevArchiveandnextArchiveThese specialized template tags are used to obtain information about the previous and next articles of the current article.The strength of these tags lies in their ability to intelligently recognize the document being viewed and automatically find the previous and next content in the same category, without the need to manually pass the article ID or category ID.

Let's take a look at how to implement this function in your Anqi CMS template.

1. Basic 'Previous/Next' text links

First, in your article detail page template file (usually located intemplate/{您的模板名称}/archive/detail.htmlOr in a similar path) find the appropriate location, usually below the article content or in the sidebar area. You can use the following code to display simple text links:

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %}
        {% if prev %}
            上一篇:<a href="{{ prev.Link }}">{{ prev.Title }}</a>
        {% else %}
            没有了
        {% endif %}
        {% endprevArchive %}
    </div>
    <div class="next-article">
        {% nextArchive next %}
        {% if next %}
            下一篇:<a href="{{ next.Link }}">{{ next.Title }}</a>
        {% else %}
            没有了
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

Code analysis:

  • {% prevArchive prev %}and{% nextArchive next %}This is the tag provided by AnQi CMS, used to retrieve the data of the previous and next articles. The data obtained will be assigned toprevandnextVariable.
  • {% if prev %}and{% if next %}In practical applications, not all articles have a previous or next article (for example, the first article in a category does not have a previous one, and the last article does not have a next one). Therefore, usingifTo judge the statementprevornextThe variable should exist to avoid displaying empty links and to provide a friendly prompt, such as 'None.'
  • {{ prev.Link }}and{{ next.Link }}: Output the link addresses of the previous and next articles.
  • {{ prev.Title }}and{{ next.Title }}: Output the title of the previous and next articles.

2. Add thumbnails to make navigation more attractive.

If your website design allows it, and articles usually include thumbnails, you can also add thumbnails to the navigation links of the previous/next articles to make them more visually appealing.

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

Code analysis:

  • {% if prev.Thumb %}and{% if next.Thumb %}Here again usedifThe statement to determine whether the article has a thumbnailThumbField). If it exists, the thumbnail is displayed.
  • {{ prev.Thumb }}and{{ next.Thumb }}Here is the thumbnail address of the article.

You can flexibly combine according to your template design and actual needsprevandnextFor example, other fields provided by the variableDescription(Description),CreatedTime(Creation time) and other, to build a more diverse navigation style. If you need to format the timestamp, you can use{{ stampToDate(item.CreatedTime, "2006-01-02") }}This kind of filter.

Positioning and design considerations

These 'Previous/Next' navigation links are usually placed at the bottom of the article content area or as a floating sidebar component.

  • Bottom navigation:Located after the main content of the article, before the comments section or related article recommendation area, to provide a natural continuation of content for users.
  • Sidebar:If the page layout has a sidebar, you can also consider displaying the simplified title of the previous/next article in the sidebar for easy user switching.

No matter which placement method you choose, you should ensure that its design style is consistent with the overall website and easy for users to recognize and click.


Frequently Asked Questions (FAQ)

1. Why does the 'Previous' or 'Next' link show 'None'?

This indicates that no earlier or later articles were found in the category of the current article.For example, if you are browsing the latest article posted under a category, there will be no 'next';Similarly, the oldest article will not have 'Previous Article'. This is a normal behavior, through{% if 变量 %}Judgment can be used to handle this situation to avoid displaying empty links.

2. Do these tags automatically limit to the same category?

Yes,prevArchiveandnextArchiveThe tag defaults to finding the previous and next articles based on the current article's category.This means you do not need any additional configuration to ensure that users do not jump to sports articles while browsing technology articles, thereby maintaining the relevance of the content.

3. Besides the title and link, what information can I display?

prevandnextThe variable contains many detailed information about the article, such asId(article ID),Keywords(Keywords),Description(Summary),Logo(Cover Image),Thumb(Thumbnail),Views(Views),CreatedTime(Publish Time) etc. You can freely call these fields in the template, for example{{ prev.Views }}or{{ stampToDate(next.CreatedTime, "2006-01-02 15:04") }}Show more article information.

Related articles

What tags does Anqi CMS provide to display content publishing or update time information?

In website content operation, the time of content release and update is a key factor in conveying information timeliness and establishing user trust.For search engine optimization (SEO), clear time information also helps improve the freshness score of the content.Anqi CMS is well-versed in this, providing users with flexible and diverse tags and methods to accurately and beautifully display these time information on the website front-end.Next, we will explore how Anqi CMS helps us manage and display the content publication and update time.###

2025-11-08

How to judge conditions in templates and dynamically display different content blocks based on logic?

In AnQiCMS, flexibly controlling the display of web page content is the key to website operators creating personalized, high-efficiency websites.The AnQiCMS template engine provides rich logical judgment and dynamic content display capabilities, allowing us to present content intelligently according to different conditions, greatly enhancing user experience and website adaptability.AnQiCMS' template syntax is clever, it absorbs the advantages of the Django template engine while also taking into account the characteristics of the Go language.

2025-11-08

How to use the pseudo-static function of Anqi CMS to optimize the display structure of URLs and improve SEO effects?

In website operation, the structure of URL (Uniform Resource Locator) has a significant impact on the SEO performance of the website.A clear, concise, and meaningful URL not only improves user experience but also helps search engines better understand and crawl web content.AnQiCMS (AnQiCMS) is well-versed in this field, providing powerful static URL features to help us easily optimize the display structure of URLs, thereby significantly enhancing SEO effects.

2025-11-08

How to configure the display of page TDK (title, keywords, description) for search engine optimization (SEO) in Anqi CMS?

It is crucial for website operation to let search engines better understand and display our content.This configuration of page TDK (Title, Description, Keywords) plays a core role.AnQi CMS provides us with flexible and powerful TDK management functions, allowing us to accurately optimize search engine optimization according to the characteristics of different pages.Next, we will learn step by step how to configure these key TDK information in Anqi CMS.### One, Global Setting of Website Homepage TDK The website homepage is the facade

2025-11-08

How to display a list of recommended content related to the current article?

In content operation, guiding users to discover more interesting content is one of the key strategies to enhance user experience and extend the time spent on the website.AnQiCMS (AnQiCMS) provides very flexible and powerful features, helping us easily achieve the goal of displaying a list of recommended content related to the current article.Why is it necessary to have relevant recommended content?

2025-11-08

How does Anqi CMS display and manage website friend links?

In website operation, friendship links play an important role. They not only help to improve the website's search engine ranking (SEO), but also bring valuable traffic, and are also a manifestation of cooperation and mutual trust between websites.Anqi CMS is well-versed in this, providing website operators with a直观 and efficient buddy link management and display solution, allowing you to easily master this feature.Next, we will delve into how to manage friend links in the background, to how to flexibly display them on the website frontend, and provide you with a detailed explanation of the friend links feature of Anqi CMS.

2025-11-08

How to display the list of user comments on articles in AnQi CMS?

In AnQi CMS, allowing users to comment on articles and clearly displaying these comments is an important aspect of enhancing the interactivity and user engagement of the website.AnQiCMS's powerful template engine and built-in features make this process flexible and efficient.This article will introduce in detail how to integrate the comment list and its related functions on the article detail page.

2025-11-08

How to build and display a custom field comment form on the front-end page?

When you want website visitors to be able to interact with you, such as submitting questions, providing feedback, or making appointments, a well-functioning contact form is essential.AnQiCMS provides a very flexible and powerful message management function, the core of which is to support custom message fields, allowing you to build personalized forms according to your actual business needs.This article will guide you on how to build and display these comment forms with custom fields on the front-end page.Why do you need a custom message form?

2025-11-08