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

Calendar 👁️ 66

When a reader visits an article of interest, they often hope to browse related or continuous content seamlessly, rather than returning to the list page to search again.Provide navigation links to "Previous" and "Next" pages on the article detail page of the website, which is an effective way to enhance this reading experience and increase user stickiness.It can not only guide users to explore the website content in depth, but can also optimize the internal link structure of the website to some extent, and is friendly to search engines.

AnQiCMS (AnQiCMS) is a powerful content management system that fully considers the needs of content operation, and therefore provides a very convenient way to implement this function at the template tag level.Even if you are not familiar with complex programming, you can easily add navigation for the previous and next articles on your article detail page by calling simple tags.

Understanding the template mechanism of Anqi CMS

The AnQi CMS adopts a template engine syntax similar to Django, which means you can control the display logic and output data through specific tags. Template tags are usually followed by{% ... %}Wrap, used for control logic (such as conditional judgment, loop), and variable output is used{{ ... }}. The links and titles of the previous and next articles are implemented through the built-in template tags of the system, which automatically search and return information about adjacent articles based on the order of the current article in the database.

Find the article detail template file

To add the navigation for the previous and next articles on the article detail page, you first need to find the corresponding template file for the article detail page. In AnQi CMS, template files are usually stored in/templateIn the directory of the theme you are currently using.

Generally, the template file path of the article detail page will be similar./template/[你的模板目录]/[你的模型table]/detail.htmlThe structure. For example, if your article uses the "article" model and the template directory name isdefault, then the file may be intemplate/default/article/detail.html.

You can edit or download these template files online through the "Template Design" feature of the AnQi CMS backend to make modifications.

Add the previous and next navigation links: Core code implementation

AnQi CMS provides two special tags for obtaining information about the previous and next articles:prevArchive(Tags of the previous document) andnextArchive(Next document tag). These tags are very smart, they do not require additional parameters to automatically identify the current article and try to retrieve the data of the previous or next article.

Information obtained from these tags is an object containing multiple fields, from which you can extract the article ID, title, link, thumbnail, etc. Common fields include:

  • Id: Unique identifier of the article
  • Title: Article title
  • Link: Access link of the article
  • Thumb: Thumbnail address of the article (if available)
  • Description: Article Summary

The following is an example of code to add previous and next navigation links to the article detail page:

<div class="article-navigation">
    <div class="prev-article">
        {% prevArchive prev %} {# 将上一篇文章信息赋值给变量prev #}
        {% if prev %} {# 判断是否存在上一篇文章 #}
            <a href="{{ prev.Link }}" title="{{ prev.Title }}">
                <span class="navigation-direction">&laquo; 上一篇</span>
                <h3 class="navigation-title">{{ prev.Title }}</h3>
                {% if prev.Thumb %} {# 如果有缩略图,则显示 #}
                    <img src="{{ prev.Thumb }}" alt="{{ prev.Title }}" class="navigation-thumbnail"/>
                {% endif %}
            </a>
        {% else %}
            <span class="navigation-direction no-more">&laquo; 没有了</span>
        {% endif %}
        {% endprevArchive %}
    </div>

    <div class="next-article">
        {% nextArchive next %} {# 将下一篇文章信息赋值给变量next #}
        {% if next %} {# 判断是否存在下一篇文章 #}
            <a href="{{ next.Link }}" title="{{ next.Title }}">
                <span class="navigation-direction">下一篇 &raquo;</span>
                <h3 class="navigation-title">{{ next.Title }}</h3>
                {% if next.Thumb %} {# 如果有缩略图,则显示 #}
                    <img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="navigation-thumbnail"/>
                {% endif %}
            </a>
        {% else %}
            <span class="navigation-direction no-more">没有了 &raquo;</span>
        {% endif %}
        {% endnextArchive %}
    </div>
</div>

In this code block:

  1. {% prevArchive prev %}and{% nextArchive next %}Load the data of the previous article and the next article separately intoprevandnextthe variable.
  2. {% if prev %}and{% if next %}This condition judgment is very important. It ensures that links are only rendered when there is indeed a previous or next article.If not found, it will display a prompt text like 'Not available', to avoid the page showing empty links.
  3. The link<a>Tag, we usedhref="{{ prev.Link }}"andtitle="{{ prev.Title }}"Display the link and title of the article.titleProperties are very helpful for user experience and search engine optimization. When the mouse hovers over them, a tooltip is displayed, and the search engine can better understand the link content.
  4. {% if prev.Thumb %}This code block allows you to optionally display a thumbnail of the previous/next article, which makes navigation more intuitive and beautiful.

Design and beautification

This code provides a basic HTML structure, you can enhance these navigation links by adding CSS styles.For example, you can place them side by side at the bottom of the page or design them as buttons with arrows. By usingarticle-navigation/prev-article/next-article/navigation-directionandnavigation-titleAdd class styles, you can integrate them into the overall design style of your website.

Summary

Provided by Anqi CMSprevArchiveandnextArchiveTemplate tag, you can integrate the previous and next navigation functions for the article detail page very flexibly and efficiently.This can greatly enhance the reading experience of users on the website, encouraging them to browse more content, and also has a positive impact on the internal link structure and SEO optimization of the website.


Frequently Asked Questions (FAQ)

1. Why did the page not display anything or only show 'none' after I added the previous/next article code?

This usually has several reasons: first, please check if the article you are currently browsing is really the first or last article in the category, if it is, then the corresponding "previous" or "next" article naturally does not exist. Second, please carefully check if the spelling of the tags and variable names in the template code is correct.{% prevArchive prev %}and{% endprevArchive %}Pair matching tags. Finally, if your website has enabled caching, please try clearing the website cache to ensure that your latest template changes have taken effect.

2. Can I display other information in the previous/next navigation besides the article title and link? For example, thumbnails or publication dates?

Of course you can.prevArchiveandnextArchiveTags retrieved from comments.prevandnextThe variable is an object that contains the complete information of the article. In addition,LinkandTitleyou can also accessThumb(thumbnail),Description(Summary),CreatedTime(Publication time) and other fields. In the code example, we have shown how to conditionally display thumbnails. You can also use them as needed,{{ stampToDate(prev.CreatedTime, "2006-01-02") }}This tag is used to format and display the publication date.

3. Does this previous/next navigation function automatically search articles across categories?

Of Security CMSprevArchiveandnextArchiveThe tag is set to find the previous and next articles in the category of the current article.This means it will maintain the relevance of the content, it will not jump to unrelated categories.If you need to implement navigation similar to cross-categories, you may need to combinearchiveList

Related articles

How to call and display custom field content in the article detail page of AnQiCMS?

In AnQiCMS, managing and displaying content, custom fields play a crucial role, enabling our website to flexibly carry various unique information, not limited to common attributes such as titles and content.Whether it is to add detailed technical parameters for product detail pages or to supplement author biographies and external reference links for articles, custom fields can provide strong support.Understand how to call and display these custom fields on the article detail page, which will greatly enhance the richness and customization of the website content. AnQiCMS

2025-11-08

How to get and display the detailed information of a single article in AnQiCMS?

Managing and displaying content in AnQiCMS is one of its core functions.It is crucial to understand how to accurately retrieve and display the detailed content of a specific article when you need to present it to visitors.AnQiCMS provides a直观 and powerful template tag system that allows you to flexibly control the layout and content of the article detail page. ### Overview of AnQiCMS Template System The AnQiCMS template uses syntax similar to the Django template engine.In the template file, you will encounter two main markers: - **Double braces

2025-11-08

How to display all documents under the current category and its subcategories in AnQiCMS template?

In AnQiCMS template design, flexibly displaying content is the key to website operation.When you need to display articles under a category page not only, but also hope to present all subcategory articles together, or display them in a more structured way, AnQiCMS provides powerful template tags to meet these needs.This article will introduce in detail how to implement this feature in your AnQiCMS template.### Understanding AnQiCMS's classification and document mechanism In AnQiCMS, content is usually organized under "document model" and "classification"

2025-11-08

How to filter and display a list of documents in AnQiCMS using custom parameters?

In AnQiCMS (AnQiCMS), when managing and displaying a large amount of content, we often need to go beyond simple categories and tags to achieve more refined content filtering.For example, a real estate website may need to filter listings by "type", "area", and "price range";An e-commerce website may need to filter products by color, size, and brand.AnQiCMS provides a powerful custom parameter feature, making it very intuitive and efficient to implement this advanced filtering.Below, we will gradually understand how to use AnQiCMS

2025-11-08

How does AnQiCMS implement intelligent recommendation and display of related articles?

In content operation, effectively recommending relevant articles to readers can not only significantly increase user stay time and page views, but also indirectly promote search engines to crawl and allocate weights to the website's content through internal link optimization.AnQi CMS is well-versed in this, providing a smart and flexible mechanism to help users easily implement the recommendation and display of related articles.How does AnQiCMS implement intelligent article recommendation?

2025-11-08

How to display the publish time and update time of articles in AnQiCMS templates?

Understand the publication and update time of an article, which not only helps readers judge the timeliness of the content and avoid outdated information, but also is an important consideration for search engine optimization (SEO).AnQiCMS as an efficient content management system provides flexible template functions, allowing you to easily display these key time information on your website.

2025-11-08

How to customize the URL static rules of the article detail page in AnQiCMS?

In website operation, a clear and friendly URL structure is crucial for search engine optimization (SEO) and user experience.AnQiCMS provides flexible URL rewriting (URL rewrite) functionality, allowing users to customize the URL format of article detail pages according to their needs.This article will introduce in detail how to customize the URL static rules for the article detail page in AnQiCMS.Why do you need to customize URL static rules?

2025-11-08

How to set the page title (Title) in AnQiCMS template and automatically append the website name?

In website operation, the page title (Title) is a crucial element, it not only directly affects the willingness of users to click in the search engine results page (SERP), but is also a key indicator for search engines to judge the relevance of page content.A clear, standardized title that includes the website brand name, which can effectively enhance the professionalism and brand recognition of the website.AnQiCMS provides a flexible and powerful mechanism for setting website titles, allowing you to easily control the title of each page and automatically attach the website name

2025-11-08