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

Calendar 👁️ 89

In website operation, the 'Previous' and 'Next' navigation function on the article detail page not only effectively improves the user's reading experience and guides them to continue browsing more content, but also has a positive impact on the website's SEO performance by building internal links.For AnQiCMS users, implementing this feature is simple and efficient.

AnQiCMS provides a直观and powerful template tag system, making it easy to display the title and link of the previous and next articles on the article detail page.You do not need to perform complex programming or database queries, just add the corresponding tags in the template file.

How to implement the previous/next navigation in AnQiCMS

AnQiCMS provides two special template tags for this:prevArchiveand the previous document"),nextArchive(The next document). The cleverness of these tags lies in their ability to intelligently identify adjacent articles based on the context of the current article, without the need to manually pass complex parameters, greatly simplifying the development and maintenance workload.

When you are using the article detail pageprevArchiveWhen the tag is used, it will automatically try to get information about the previous article of the current article; similarly,nextArchiveThe tag will retrieve the next article. If there is no previous or next article (for example, if the current article is the first or last in the category), these tags will return empty values, allowing us to flexibly handle this situation in the template, for example, by displaying a friendly prompt.

Add navigation code in the template

Generally, we would add the template code for the article detail page (for example, depending on your content model, it might bearticle/detail.htmlorproduct/detail.htmlAdd the following code snippet to the bottom of the content area or any location where you want to display navigation.

First, let's take a look at the simplest implementation, which will display the title and link of the previous and next articles:

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

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

Code explanation:

  • {% prevArchive prev %}This tag is used to get the data of the previous article. Here we will assign the data obtained to a variable namedprevThe variable. You can choose other variable names to your liking, but make sure to keep them consistent in subsequent code.
  • {% if prev %}: This is a conditional judgment statement. It checksprevDoes the variable have a value. If there is a value (i.e., there is an article from the previous one), then executeifThe code inside the statement block.
  • <a href="{{prev.Link}}" title="{{prev.Title}}">上一篇:{{prev.Title}}</a>This line of code creates a hyperlink.{{prev.Link}}It will output the URL of the previous article, and{{prev.Title}}it will display the title.
  • {% else %}If:prevIf the variable is empty (i.e., there is no previous article), then executeelseCode within the block, which shows “No previous article.”
  • {% endprevArchive %}and{% endif %}: are used to endprevArchiveTags andifConditional judgment.
  • nextArchiveThe way of using tags andprevArchiveExactly the same, but it processes the data of the next article and assigns it tonextVariable.

By this concise code, you can easily add navigation to the previous and next articles at the bottom of the article detail page.To enhance the user experience, it is recommended that you add appropriate CSS styles to the navigation of the previous/next article, making it more prominent and easy to click on the page.

Further customization and optimization

Provided by AnQiCMSprevArchiveandnextArchiveTags are not limited to displaying titles and links. They also support outputting other fields, making your navigation more rich and attractive.For example, you can display the thumbnail, publish time, and other information of the article.

  • Show thumbnail:If you want to display the thumbnail of the article in the navigation, you can consider in<a>in the tag.<img src="{{prev.Thumb}}" alt="{{prev.Title}}">as long as your article has set the thumbnail in the background.
  • Display the publish time:You can use{{stampToDate(prev.CreatedTime, "2006-01-02")}}Show the publication date of the previous article to make it more specific.
  • Handle articles without adjacent articles:When there is no previous or next article, as shown in the example, display a friendly prompt message (such as "No previous article"), avoid blank pages or error display, and improve user experience.

By these flexible tags, you can freely customize the navigation style and content of the previous and next articles according to the overall design and content display requirements of the website.

Summary

In AnQiCMS, adding navigation functions for the previous and next articles on the article detail page is a simple and effective strategy to enhance user experience and website SEO. By utilizingprevArchiveandnextArchiveThese template tags allow you to build beautiful and practical content navigation with great efficiency, allowing your readers to navigate the website effortlessly.


Frequently Asked Questions (FAQ)

Q1: Why do some article detail pages show 'No previous article' or 'No next article'?

A1:This usually has several cases. First, if the current article is the first article in the category of your website, then there is no previous article content;On the contrary, if it is the last one, there is no 'next one'.Secondly, these navigation tags of AnQiCMS are sorted according to the publication time or ID of the articles. If adjacent articles are deleted, or the publication order is 'discontinuous', it may also cause the display of 'nothing'.

Q2: Can I customize the display order of the previous/next article, such as sorting by views?

A2: prevArchiveandnextArchiveThe tag itself mainly works based on the direct adjacent relationship of the current article in the time or ID sequence, without built-in parameters to directly change the sorting logic (such as by views). If you need a more complex sorting logic to get the previous or next recommended article, you may need to consider usingarchiveListLabel, combining the current article ID and category ID, get a list sorted according to specific rules, and then manually select adjacent articles. This will be more than using directlyprevArchiveandnextArchiveMore complex, usually the default order is sufficient in most cases.

Q3: Besides the title and link, can I display other information in the navigation of the previous/next article?

A3:Of course you can.prevandnextThe variable (defined in the template) is a complete article object, you can access its multiple fields, such as:

  • {{prev.Thumb}}: Display the thumbnail of the previous article.
  • {{stampToDate(prev.CreatedTime, "2006-01-02")}}: Display the publication date of the previous article.
  • {{prev.Description}}: Display a brief description of the previous article. You just need to in<a>Labels or other HTML elements, introduce these fields according to your design requirements.

Related articles

How to use AnQiCMS template tags to dynamically display content data on the front-end page?

## Easily navigate AnQiCMS template tags: make your website content come alive!In today's digital world, a website that can dynamically display content is much more attractive to visitors and improves user experience than a static page.AnQiCMS (AnQiCMS) provides us with a powerful and intuitive template tag system that allows us to flexibly display backend data on the website front-end without writing complex code.This is like having a series of spells that, with a few taps, can bring the website content to life.The template tag design of AnQiCMS has borrowed the syntax of Django template engine

2025-11-07

How should the template files of AnQiCMS be organized and named to achieve flexible content display?

When using AnQiCMS to build a website, the organization and naming of template files are key to flexible content display, improving website maintenance efficiency and scalability.A well-structured and clearly named template system that not only allows you to easily manage various content types, but also lays a solid foundation for future functional expansion. ### Template File Storage and Basic Conventions AnQiCMS's template system uses a template engine syntax similar to Django, which makes it very亲切 for those familiar with front-end development.All template files should use the `.html` file extension uniformly

2025-11-07

How to customize the display layout and template file path for articles (or other content) in AnQiCMS?

In AnQiCMS, your website content display has high flexibility.Whether it is an article, product details, or an independent page, you can tailor the display layout and template file path according to the brand image, content characteristics, or specific operational needs.This design concept of AnQiCMS aims to help users break free from the constraints of traditional CMS and have more freedom to control the visual presentation and user experience of the website.

2025-11-07

What front-end display modes does AnQiCMS support to manage PC and mobile websites?

In the digital age, it is crucial to provide an excellent user experience whether visitors browse your website on a computer or mobile phone.A high-efficiency content management system should be able to flexibly meet this diverse display demand.AnQiCMS is designed for this, it provides various front-end display modes, allowing you to finely manage the display effects of PC and mobile websites according to your actual business needs.AnQiCMS provides three main display modes on the website frontend, each with unique advantages and applicable scenarios, helping you build a modern website adaptable to different devices

2025-11-07

How to display the system name configured in the background of AnQiCMS website?

Conveniently display the system name configured in the AnQiCMS website The system name of the website is a core component of its online identity, it is not just a simple name, but also a key to brand image, search engine optimization (SEO) and user identification.For AnQiCMS users, displaying the system name configured in the background on the website frontend can ensure consistency of website information, enhance user experience, and improve search engine friendliness.

2025-11-07

How to dynamically retrieve and display the website logo image address in AnQiCMS templates?

In web design, the logo is not just a symbol of the brand, it is also the core of the website's recognition.For a content management system like AnQiCMS, the ability to flexibly call and display the website logo in templates is the key to improving operational efficiency and maintaining brand consistency.The good news is that AnQiCMS provides a very intuitive and powerful way to dynamically retrieve and display the image address of your website's Logo, allowing you to easily manage your brand image without touching the core code.

2025-11-07

How to display the filing number and copyright information at the bottom of the AnQiCMS website?

In website operation, the information display at the bottom of the website, especially the filing number and copyright statement, is not only an embodiment of website compliance, but also an important way to convey trust and professionalism to visitors.For websites built using AnQiCMS, it is a fundamental operation to display these key information flexibly and efficiently at the bottom of the website, which is the basis for improving user experience and meeting legal and regulatory requirements.

2025-11-07

How does the AnQiCMS template display the base URL address of the current website?

In website operation and template development, accurately obtaining and displaying the basic URL address of the current website is a very basic but important requirement.It is crucial to understand how to flexibly call the basic URL of the website in AnQiCMS template, whether it is for correctly loading the static resources of the website (such as CSS, JavaScript, and images), or for building dynamic internal links, or for generating Canonical URL in accordance with SEO standards.AnQiCMS as an efficient and customizable content management system, fully considers this requirement

2025-11-07