How to implement navigation between previous and next document sections using the `prevArchive` and `nextArchive` tags?

Ease your way: How to use Anqi CMSprevArchiveandnextArchiveTag to implement intelligent article navigation

As experienced website operators, we know that website content is not just about publishing, but how to let users browse smoothly in a vast amount of information and find the next article they are interested in is the key to improving user experience, extending stay time, and even optimizing SEO. In the powerful and flexible content management system AnQiCMS, ...prevArchiveandnextArchiveThese template tags are exactly the tools to achieve seamless navigation.

AnQi CMS, with its high-performance architecture based on the Go language and modular design, provides efficient and customizable content solutions for small and medium-sized enterprises and content operation teams.Its SEO-friendly features, as well as flexible template engine syntax, make it easy for content creators and developers to build outstanding websites.Today we will delve into the navigation of the previous and next documents, which is a microcosm of its excellent user experience design.

Why is the navigation between parts so important?

Imagine a user coming to an article on your website through a search engine.If this article has high-quality content, users are likely to be interested in reading related content.At this time, a prominent 'Previous' and 'Next' navigation, as if building a series of bridges across the content river for users.It can not only guide users to deeply browse the website, reduce the bounce rate, but also naturally increase the PV (Page View) of the page, form a good in-site link structure, which is of great benefit to the search engine's crawling and weight transmission.

For self-media operators, it can effectively improve the internal circulation efficiency of the content matrix; for corporate websites, it can help potential customers understand the details of products or services in an orderly manner, from introduction to application, to case studies, forming a complete cognitive path.

RevelationprevArchiveandnextArchiveTag

The AnQi CMS template system uses a syntax similar to the Django template engine, which is simple and powerful.prevArchiveandnextArchiveThe design of the label, which fully implements the concept of "user-centered": it's characterized by intelligence and simplicity:No parameters are requiredThese two tags can automatically identify the context of the current document and intelligently find the previous and next documents in the category or timeline it belongs to.

This means that when you use these tags on the document detail page, the system will automatically judge the relationship between the current document and provide the corresponding document data, greatly simplifying the complexity of template development.

Let's take a look at their basic usage:

{# 获取上一篇文档 #}
{% prevArchive prev %}
  {# 在这里编写上一篇文档的HTML结构 #}
{% endprevArchive %}

{# 获取下一篇文档 #}
{% nextArchive next %}
  {# 在这里编写下一篇文档的HTML结构 #}
{% endnextArchive %}

Between these two tag pairs, you can access the objects representing the previous or next document (in the example, they are the respective objects for the previous and next documents)prevandnext),and by the dot(.)to access various properties of these documents.

Learn more about the available data fields

prevandnextThe object provides rich document information, enough for us to build a beautiful and practical navigation link. The following are some common fields:

  • Id: The unique ID of the document.
  • Title: Document title. This is the most commonly used and most important display content.
  • Link: Document URL link. The address where users navigate when they click.
  • Description: The document's introduction or description. It can be displayed as supplementary information in navigation.
  • Thumb: The thumbnail address of the document. If the design allows, displaying a thumbnail can enhance visual appeal.
  • CategoryId: ID of document's category.
  • Views: Document's view count.

Combining these fields, we can easily build personalized navigation blocks. It is worth noting that not all documents have "Previous" or "Next" (for example, the first article in a category does not have "Previous", and the last article does not have "Next"), and we usually combine these tags when using them.ifConditional judgment to ensure that navigation is only displayed when data exists.

Practical case: Creating an elegant navigation block

Suppose we want to add a left and right column navigation block at the bottom of each article, with the left column being 'Previous article' and the right column being 'Next article'. If there are no more articles in one direction, it will display 'None' or 'Back to list'.

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

    <div class="next-article">
        {% nextArchive next %}
            {% if next %}
                <a href="{{ next.Link }}" title="{{ next.Title }}">
                    <span class="nav-label">下一篇:</span>
                    <h4 class="nav-title">{{ next.Title }}</h4>
                    {% if next.Thumb %}
                        <img src="{{ next.Thumb }}" alt="{{ next.Title }}" class="nav-thumb">
                    {% endif %}
                </a>
            {% else %}
                <span class="no-more">没有下一篇了</span>
            {% endif %}
        {% endnextArchive %}
    </div>
</div>

By such a code structure, we not only achieved the basic up and down navigation function, but also provided users with a richer and more friendly browsing experience through conditional judgment and flexible field invocation. When the mouse hovers over the navigation link, its title attribute (title) It can also provide more information, balancing accessibility and user-friendliness.

Summary

Of Security CMSprevArchiveandnextArchiveLabel, with its parameterless, automatically context-aware intelligent design, greatly simplifies the implementation of website article navigation.They not only help us build a smooth content flow experience, enhance users' stay time on the website and the efficiency of content discovery, but also lay a solid foundation for the website's SEO optimization.For any website operator who wants to provide an excellent user experience and efficient content management, mastering these two tags is undoubtedly an important part of the safe CMS content operation strategy.


Frequently Asked Questions (FAQ)

Q1: If a category has only one article, or the current article is the first/last article in the category,prevArchiveandnextArchiveHow will the tag perform?

A1: As mentioned in the article,prevArchiveandnextArchiveTags do not return any data when there is no corresponding document. Therefore, **it is always recommended to use{% if prev %}or{% if next %}This conditional judgment wraps the output of the navigation link. If the judgment is false (i.e., there is no previous or next article), you can choose to display a prompt text (such as "None") or provide a link back to the current category list page to guide the user to continue browsing.

Q2:prevArchiveandnextArchiveCan the tag implement cross-category navigation for previous and next articles? For example, if the current article belongs to Category A, but I want the 'next article' link to go to an article in Category B?

A2:prevArchiveandnextArchiveLabels are usually in the context of the current document(such as the same category, the same model)Look for the previous and next chapters. They are designed to provide navigation within a logically continuous content stream.If you need to implement cross-category navigation between previous and next articles, or define 'previous' and 'next' articles based on more complex logic (such as specific tags, publication time order instead of category order), you may need to combinearchiveListTags for more advanced customization development. This usually involves querying a list of documents under specific conditions, then manually calculating the target document ID and link based on the current document ID and sorting rules, which is more complex than directly using these two tags.

Q3: UseprevArchiveandnextArchiveWill the label affect the website performance?

A3: Will not. Anqí CMS is developed based on Go language, famous for its excellent high concurrency processing capability and lightweight features.prevArchiveandnextArchiveThe tag has been highly optimized at the bottom level, allowing for efficient querying and returning of data.Moreover, AnQi CMS supports various optimization measures such as static caching, further ensuring that the website can maintain extremely fast loading speed and response performance when handling these dynamic contents, with almost negligible impact on overall website performance.