How can you easily obtain and display the link and title of the previous and next articles on the article detail page?

Calendar 👁️ 107

As an experienced website operator familiar with AnQiCMS, I fully understand the importance of effectively guiding users to browse and discover more content in content management.The previous/next article navigation on the article detail page can not only significantly improve user experience and extend the time users stay on the site, but also help optimize the internal link structure of the website, which is very beneficial for SEO.Next, I will elaborate on how to conveniently and quickly obtain and display the links and titles of the previous and next articles on the article detail page of AnQiCMS.


Enhance user experience and content discovery: Implement navigation to previous/next article in AnQiCMS article detail page

Today, with the increasing richness of digital content, whether it is a corporate website, a self-media blog, or a product showcase platform, they all face the challenge of how to effectively organize content and guide users to in-depth browsing.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides intuitive template tags, allowing us to easily implement the navigation function for the previous and next articles on the article detail page.This not only allows visitors to naturally discover more related information after reading the current content, but also builds a strong internal link network, improving the efficiency and ranking performance of search engines in capturing website content.

The Anqi CMS template system has borrowed the syntax of the Django template engine, with.htmlas the template file suffix, and stored in/templatedirectory. The tags use double curly braces{{变量}}Define variables, while control flow tags such as conditional judgment and loops use single curly braces and percent signs{% 标签 %}Understanding this foundation is the key to custom content display.

Use built-in tags to get adjacent article information

In AnQiCMS, to get the previous and next articles of the current article, it mainly relies on two core template tags: prevArchiveandnextArchive. These tags are designed to be simple and efficient, requiring no complex parameter configuration to automatically identify the current article and find the adjacent articles in the category or publication sequence.

prevArchiveThe tag is used to get the previous article of the current article. When you use this tag on the article detail page, it will automatically identify the article on the current page and find the article sorted before it.Similarly,nextArchiveThe tag is used to retrieve the next article data of the current article, it will find the article sorted after the current article.

These tags provide a very rich set of data fields, including but not limited to the articles'Id(ID),Title(Title),Link(Link),Keywords(Keywords),Description(Description),CategoryId(Category ID),Views(Views),Logo(Cover main image),Thumb(Cover Thumbnail),CommentCount(number of comments) as well as the creation and update time of the articlesCreatedTimeandUpdatedTimeThese fields are enough to support the construction of a fully functional previous/next navigation.

The specific steps to implement the previous/next article navigation in the article detail page.

To display the links and titles of the previous and next articles on the article detail page, we first need to locate the corresponding template file. Usually, the template file for the article detail page will be{模型table}/detail.htmlFor example, if your article model is "article", then the template may be located atarticle/detail.html.

After finding and opening this template file, you can add the following code below the article content, in the sidebar, or any location where you wish to display these navigations:

Show the link and title of the previous article

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

In this code, we first use{% prevArchive prev %}Assign the data of the previous article to a variable namedprevThen, through a{% if prev %}The condition is to ensure that the link and title are rendered only when there is a previous article.{{ prev.Link }}The URL of the article will be output, and{{ prev.Title }}Then display the title of the article. If you do not need additional text prompts, you can remove the "Previous:" as per your actual design.

Display the link and title of the next article.

Next, we can add the navigation for the next article in a similar manner:

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

Similarly,{% nextArchive next %}Assign the data of the next article tonexta variable, and use{% if next %}Perform conditional judgment.{{ next.Link }}and{{ next.Title }}to output the link and title of the next article separately.

Further optimization and consideration.

To provide a richer user experience, you can also choose to add a thumbnail of the article to the link.prevArchiveandnextArchiveTags are provided.Thumb(Thumbnail) andLogo(Cover main image) field. For example, you can modify the code to display thumbnails:

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

By such implementation, not only does the page content become more visually appealing, but it also provides users with more intuitive navigation cues.The addition of these navigation elements can effectively extend the user's stay on the website, encouraging them to explore more content, thereby indirectly enhancing the overall exposure and search engine friendliness of the website's content.When designing these navigation, you can also use CSS to style it beautifully, making it consistent with the overall design style of the website and providing a smoother browsing experience.


Frequently Asked Questions

Q1: How does AnQiCMS decide the order of 'previous' and 'next' articles?A1: AnQiCMS usually decides based on the publication time of the articles (CreatedTime)or the sort value set in the background(orderfield such asid descorsort descTo determine the previous and next articles. By default, the system sorts according to the article ID or publication time and finds adjacent articles within the same category.This means, if you want to control their order precisely, you can adjust the publication time when posting the article or use the article sorting function in the backend.

Q2: If the current article is the first or last article in the category, what will the previous/next article navigation display?A2: As shown in the article, when there is no previous article,{% if prev %}The condition will be false, you can customize the display of "none" or not display the navigation at all. Similarly, when there is no next article,{% if next %}The condition will also be false, you can also customize the display accordingly. This condition judgment mechanism ensures the robustness of page navigation, avoiding the display of empty links or error information.

Q3: Can I customize the style and layout of the previous/next article link?A3: Of course you can. The AnQiCMS template system allows you to fully control the output HTML structure. You can wrap the link in.divOr add a custom CSS class to other HTML elements (such asarticle-navigation,prev-article,next-article),Then define the styles for these classes in your CSS file, including font, color, background, borders, icons, etc., to keep them consistent with your website design.You can also adjust the arrangement of elements within the link according to your needs, such as placing the thumbnail above or next to the title.

Related articles

How to display the title, content, images, and other detailed information of the current content on an article or product detail page?

As a senior security CMS website operator, I know that the content detail page is a core component of the website, carrying the important mission of displaying key information such as products and articles to users.A well-designed, comprehensive detail page that not only effectively conveys content value but also enhances user experience and SEO performance.Strong and flexible template tags provided by Anqi CMS, allowing us to easily control the display of each item on the page.

2025-11-06

How to get the list of the latest published or articles/products under a specified category?

As an experienced AnQiCMS (AnQiCMS) website operator, I am well aware of the importance of content presentation for website user experience and the effectiveness of content marketing.AnQi CMS provides a powerful and flexible template tag system that allows us to easily retrieve and display various types of articles and product lists, whether it is for the latest content updates or for special topic displays under specific categories, all can be achieved through simple configuration.

2025-11-06

How to get and display the title, content, and link of a specific single-page?

As an experienced CMS website operation person, I know that content is the soul of the website, and how to efficiently and accurately display content is a crucial link in our daily work.In Anqi CMS, a single page usually carries the core information of the company introduction, contact information, service description, etc., and its content often needs to be specifically retrieved and displayed in various corners of the website.Today, let's discuss in detail how to obtain and display the title, content, and link of a specific single page in Anqi CMS.

2025-11-06

How to get the list of all single-page lists of a website?

As an experienced CMS website operation personnel of an enterprise, I know the importance of acquiring and managing website content, especially for single pages carrying core information such as 'About Us', 'Contact Information', or 'Terms of Service'.In AnQi CMS, the system provides an efficient and flexible way to obtain the list of these single pages, so that we can integrate them into website navigation, site map, or other display locations.

2025-11-06

How to display a list of recommended articles related to the current article on the article detail page?

As an experienced security CMS website operator, I fully understand the importance of high-quality content and refined operation for user retention and website SEO.Display related recommended articles on the article detail page, which can not only effectively extend the user's time on the site and reduce the bounce rate, but also optimize through internal links, improve the overall weight of the website, and is an indispensable part of content operation.Below, I will give a detailed introduction on how to implement this feature in Anqi CMS.

2025-11-06

How to retrieve the custom field parameters defined in the content model and filter and display them?

As an experienced CMS website operation person in an enterprise, I know how important the custom field function of the content model is for building rich and personalized website content.It can not only help us organize information flexibly, but also provide users with more accurate filtering and display experience.I will explain in detail how to obtain the custom field parameters of the content model definition in Anqi CMS and perform effective filtering and display. ### Create and manage custom content model fields Firstly, all functions are based on the configuration in the background.In AnQi CMS

2025-11-06

How to display a list of tags and their details for all or specific articles on a website?

Hello!As an experienced CMS website operator, I fully understand your needs for the Tag feature in terms of content organization and optimization.Tags are an indispensable part of website content management, as they not only help users find relevant content faster, but also effectively improve the website's SEO performance.Below, I will elaborate on how to display the tag list and detailed information of all or specified articles on the AnQiCMS website.

2025-11-06

How to get and display the list of all documents under a specific Tag tag?

As a website operator who deeply understands the operation of AnQiCMS, I fully understand the importance of efficient content management and optimization.Tags (Tag) are one of the key elements for organizing content, improving user experience, and enhancing SEO performance.By using tags, we can not only provide readers with more accurate content aggregation, but also help search engines better understand the structure of the website content.I will elaborate in detail on how to retrieve and display the list of all documents under a specific Tag label in AnQiCMS.

2025-11-06