How to call and display the title and link of the previous and next articles on the article detail page?

Calendar 👁️ 74

In AnQiCMS, adding navigation for the previous and next articles on the article detail page is an important link to enhance the user reading experience and optimize the internal link structure of the website.This feature not only guides readers to continue browsing related content, but also helps search engines better understand the website structure.AnQiCMS powerful template system provides a very convenient way to meet this requirement.

AnQiCMS template basic review

The AnQiCMS template system is simple and efficient, using syntax similar to Django, allowing developers to build pages intuitively. All template files are usually written in.htmlsuffix and stored in/templateIn the corresponding subject folder{模型table}/detail.htmlFor example, the detail page of the article model might bearticle/detail.htmlIn these template files, we use double curly braces{{变量}}Output variable content, using single curly braces and percent signs{% 标签 %}Use built-in template tags for logical control and data calling

Call the title and link of the previous article

To display the title and link of the previous article on the article detail page, AnQiCMS provides a specialprevArchiveThe tag does not require any additional parameters, it will automatically find and return the data of the previous article based on the order of the current article in the category or global list.

UseprevArchiveWhen labeling, we usually assign its result to a variable, for exampleprev, and then access various properties of the previous article through this variable, such as the title and link.

Here is an example of calling the previous article in a template:

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

In this code block:

  • {% prevArchive prev %}: means that the data obtained from the previous article will be assigned to a variable namedprev.
  • {% if prev %}: is a conditional judgment, checkingprevDoes the variable exist. This is an important step, because if the current article is the first in the list, then there is no 'previous one', at this timeprevThe variable will be empty. Through this judgment, we can avoid page errors and display friendly prompts such as 'There is no previous article'.
  • {{ prev.Link }}Displays the URL link of the previous article.
  • {{ prev.Title }}Displays the title of the previous article.

Calls the title and link of the next article.

Similar to the calling method of the previous article, AnQiCMS also provides exclusive for the next articlenextArchiveThe working method of this tag is similar toprevArchiveThe same, it will also automatically find the next article's data according to the order of the current article.

You can usenextArchiveThe result of the tag is assigned to a variable, for examplenextThen operate likeprevThe variable is the same, accessing the title and link of the next article.

Here is the example code to call the next article.

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

This code's logic is exactly the same as that of the previous article, only the variable names have been changed fromprevtonext, and the link and title both point to the next article.{% if next %}It is used to determine if the next article exists, to handle the case at the end of the list.

Complete code example

Integrate the navigation of the previous and next articles to the bottom of the article detail page, which usually makes the page layout more reasonable and better guides users. Here is a complete example showing how to do it in yourdetail.htmlThese tags are used in the template:

{# 假设这是您的文章详情内容区域结束之后 #}
<div class="article-navigation">
    {% prevArchive prev %}
    <div class="prev-article">
        {% if prev %}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                <span class="icon">←</span> 上一篇:{{ prev.Title }}
            </a>
        {% else %}
            <span class="no-entry">← 没有上一篇文章了</span>
        {% endif %}
    </div>
    {% endprevArchive %}

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

{# 您可能还需要为 .article-navigation, .prev-article, .next-article, .no-entry, .icon 等类添加CSS样式,以美化显示效果。 #}

By making such settings, your AnQiCMS website article detail page will have a convenient navigation function for the previous/next article.The introduction of these tags not only simplifies the template development process, but also provides strong support for building a user-friendly and SEO-optimized content platform.


Frequently Asked Questions (FAQ)

  1. Why sometimes the 'Previous' or 'Next' links do not display on the article detail page?This is usually because the current article is at the beginning or end of its list.If the current article is the first one in the list, there is no 'previous article';If it is the last one, there is no 'next one'. In the above code example, we use{% if prev %}and{% if next %}This condition judgment is used to handle this situation, when there is no corresponding article, it will display a prompt such as 'There is no previous article' or 'There is no next article' instead of a link.

  2. Can I also call other information from the previous/next article, in addition to the title and link?Of course you can.prevArchiveandnextArchiveThe variable returned by the tag (for exampleprevandnext) contains multiple article data, such asId(article ID),Description(article description),Thumb(thumbnail),Views(Views),CreatedTime(publish time) etc. You can use the template as needed by means of{{ prev.Thumb }}or{{ next.Description }}In order to call this information, further enrich the navigation display content, for example, displaying thumbnails or brief descriptions.

  3. How is the sorting logic for the previous and next articles? Can I customize it?AnQiCMS'prevArchiveandnextArchiveThe tag is usually determined by the order of the article's publication (usually by ID or publication time).This means they will automatically handle most of the cases. If your website has more complex sorting logic requirements (such as by page views, weight, etc.), and you want the 'Previous/Next' navigation to follow this logic, thenprevArchiveandnextArchiveIt may not be directly satisfied. In this case, you may need to combinearchiveListTag for more advanced custom queries, by specifyingorderParameters and manually calculate the current article's index to simulate the "previous/next" logic, but this is relatively complex. For most websites, the default order is sufficient.

Related articles

How to use AnQiCMS's pseudo-static rules to optimize the display structure of article URLs to improve SEO?

In website operation, the URL is not only the entrance for users to access content, but also an important basis for search engines to understand and crawl website content.A clear and semantically friendly URL can significantly improve user experience and website performance in search engines.One of the key factors to achieve this goal is to skillfully use pseudo-static technology.AnQiCMS as a high-efficiency and customizable content management system, fully considers the needs of SEO optimization, and provides powerful and flexible pseudo-static rule configuration functions. Today

2025-11-09

How does the multi-site feature of AnQiCMS affect the display and switching of front-end content?

When using a website content management system, the multi-site feature has always been a topic of concern.It not only concerns the operational efficiency, but also directly affects the organization, display of website content, and the smooth switching experience of users between different sites.For AnQiCMS users, its powerful multi-site feature is the tool to solve these challenges.Let's delve into how the multi-site feature of AnQiCMS affects the display and switching of front-end content.One of the design初衷 of AnQiCMS is to meet the needs of users managing multiple brands, sub-sites, or multilingual content

2025-11-09

How to use template tags to dynamically display the associated Tag list in article content?

How can we make users see the related keywords or topic list in an article at a glance while browsing, so as to guide them to discover more interesting content and thus improve user experience and website stickiness, which is an important link.AnQiCMS (AnQiCMS) provides powerful template tag features, allowing you to easily display related Tag lists dynamically in article content, which is both beautiful and practical.**Understanding the Tag Function of AnQi CMS** Tags in AnQi CMS are not just simple classifications of articles

2025-11-09

How to configure AnQiCMS to enable lazy loading of images on the page?

In today's rich network world, the speed of website loading is of great importance to user experience and search engine optimization (SEO).Especially when a page contains a large number of images, how to effectively manage the loading of these images, avoid the lag caused by loading all resources at once, has become a focus of many website operators.The Lazy Load (Lazy Load) technology is the tool to solve this problem, it allows images to be loaded only when the user is about to see them, thus significantly improving page performance.AnQiCMS as a high-performance content management system

2025-11-09

Does AnQiCMS support displaying the number of articles under each category on the category list page?

When operating a website, we often encounter such needs: when displaying the website category list, we hope to see intuitively how many articles are under each category.This not only helps visitors quickly understand the richness of a topic's content, improve user experience, but also enables us content operators to better plan content strategies, and even has unique value in SEO optimization. Then, does AnQiCMS support displaying the number of articles under each category on the category list page?The answer is affirmative, and it is very convenient to implement. In the template design of AnQiCMS

2025-11-09

How to set up a dynamic carousel effect for the Banner image on the homepage of AnQiCMS website?

In AnQiCMS, setting a dynamic banner slideshow on the homepage can effectively enhance the visual appeal of the website and convey key information.AnQiCMS provides flexible and intuitive features to help us achieve this goal.Next, we will step by step understand how to set up from the background to the front-end template editing, creating an animated carousel effect for the homepage.### 1. Backend configuration of Banner image: Content and grouping Firstly, we need to prepare the images and relevant information for the carousel in the AnQiCMS backend

2025-11-09

How to control the number of characters displayed for the article abstract (Description) in the list and automatically add an ellipsis in AnQiCMS?

When operating website content, the display length of the article summary (Description) on the list page is crucial for the neatness of the page and the user experience.A long summary can make the page look bloated and difficult to browse quickly, while a short one may not attract readers to click.AnQiCMS as a feature-rich content management system, provides flexible template tags and filters, allowing us to easily implement precise control over the word count displayed in article summaries and automatically add elegant ellipses.###

2025-11-09

How to implement conditional judgment in a template, for example, whether to display an image based on whether the article has a thumbnail?

In website content presentation, images play a crucial role.However, not all content has corresponding thumbnails, or for design aesthetics and loading speed considerations, we may need to decide based on the actual situation whether to display images, or even display different placeholders.AnqiCMS provides a flexible and powerful template engine, allowing us to easily implement this conditional image display logic, thereby enhancing the flexibility and user experience of website content.This article will focus on how to decide whether to display an image in the AnqiCMS template based on whether the article has a thumbnail

2025-11-09