How to add custom CSS styles or HTML attributes to the link generated by the `prevArchive` tag?

Calendar 👁️ 57

As an experienced website operations expert, I am well aware of the importance of meticulous template customization in content management systems for improving user experience and the overall style of the website.AnQiCMS (AnQiCMS) provides us with great flexibility with its efficient architecture based on the Go language and a Django-like template engine.prevArchiveThe link generated by the "Previous Article" tag adds custom CSS styles or HTML attributes.


Refined craftsmanship: Customizing the Anqi CMSprevArchiveCSS styles and HTML attributes of the link

In modern web design, navigation is not only about functionality, but also a crucial component of user experience and brand image. Anqi CMS'sprevArchiveTags can help us easily display the 'Previous Article' link on the article detail page, guiding users to continue browsing.However, the default links generated are often plain and unadorned.As website operators, we naturally hope that these links can maintain consistency with the overall design style of the website, and even enhance their functionality or improve SEO performance by adding additional attributes.

How should we expose it in the Anqi CMS template?prevArchiveHow to inject custom CSS styles or HTML attributes into links generated by tags?The core is to understand the template working mode of Anqi CMS, especially how tags provide data, and how we can use this data to build custom HTML structures.

UnderstandingprevArchiveHow the tag works

First, let's reviewprevArchiveThe basic usage of tags.According to the Anqi CMS documentation, its main responsibility is to retrieve the data of the 'previous' document of the current document.prevThen we can render this information through conditional judgment.

The typical usage is as follows:

{% prevArchive prev %}
{% if prev %}
  <a href="{{prev.Link}}">{{prev.Title}}</a>
{% else %}
  <!-- 没有上一篇文章时的内容 -->
  <span>已经是第一篇文章了</span>
{% endif %}
{% endprevArchive %}

This code shows that what we can really manipulate is{% if prev %}and{% else %}the HTML structure inside the block.prevArchiveThe tag only provides data, the specific link elements.<a>It is manually written by us. This is the entry point for us to customize styles and properties.

Core strategy: directly build HTML and utilize CSS

SinceprevArchiveThe tag provides data rather than predefined HTML elements, our customization strategy is very clear: in the template, usingprevdata provided by variables, built completely according to the requirements<a>Label, and add the required CSS classes, inline styles, or HTML attributes during construction.

  1. Add CSS classes (recommended practice)

    Adding CSS classes to links is the most common and recommended practice.It separates style from structure, making it easier to manage and maintain, and also facilitates responsive design and future style adjustments.You can define these classes in the theme's CSS file and then directly refer to them in the template.

    For example, if you want the link to the 'previous article' to be displayed in blue bold and have a bottom border, you can first in your theme'spublic/static/css/style.cssIn a (or any custom CSS file) define a class:

    /* public/static/css/style.css */
    .prev-archive-link {
        color: #007bff; /* 蓝色 */
        font-weight: bold;
        text-decoration: none;
        padding-bottom: 3px;
        border-bottom: 1px solid #007bff;
        transition: color 0.3s ease, border-bottom 0.3s ease;
    }
    
    .prev-archive-link:hover {
        color: #0056b3; /* 鼠标悬停时的深蓝色 */
        border-bottom-color: #0056b3;
    }
    

    Then in your article detail template (such as){模型table}/detail.html), modifyprevArchivein the call part, add this CSS class to the<a>tag:

    {% prevArchive prev %}
    {% if prev %}
      <a href="{{ prev.Link }}" class="prev-archive-link">{{ prev.Title }}</a>
    {% else %}
      <span class="no-prev-archive">已经是第一篇文章了</span>
    {% endif %}
    {% endprevArchive %}
    

    This will automatically own the link to your "previous article".prev-archive-linkAll styles defined by the class.

  2. Add inline styles (use discretion).

    Although CSS classes are preferred, in some very special, one-time situations, you may need to use direct<a>Add inline styles to the tag. Please note that overusing inline styles can make CSS management chaotic and may lead to performance issues.

    If you indeed need to, you can do it like this:

    {% prevArchive prev %}
    {% if prev %}
      <a href="{{ prev.Link }}" style="color: purple; font-size: 1.1em; text-decoration: underline;">{{ prev.Title }}</a>
    {% else %}
      <span style="color: grey;">已经是第一篇文章了</span>
    {% endif %}
    {% endprevArchive %}
    

    here,styleThe property is directly assigned CSS rules, the link will immediately apply these styles.

  3. Add custom HTML attributes

    In addition to style, we can also add various HTML attributes to links, including standard HTML attributes (such astarget="_blank"/rel="nofollow") as well as custom attributesdata-*properties, to meet specific interactive or SEO requirements.

    • Standard HTML attributes:For example, you may want the link to open in a new tab in certain situations, or addaria-labelTo improve accessibility.

      {% prevArchive prev %}
      {% if prev %}
        <a href="{{ prev.Link }}" class="prev-archive-link" target="_self" aria-label="阅读上一篇文章:{{ prev.Title }}">{{ prev.Title }}</a>
      {% else %}
        <span class="no-prev-archive">已经是第一篇文章了</span>
      {% endif %}
      {% endprevArchive %}
      

      Please note that for the "Previous" link within the site, it is usually not necessary.target="_blank"(Opened in a new tab), as this may interfere with the user's current browsing process.target="_self"It is the default behavior, which can be omitted.aria-labelIt can provide more context information for screen readers.

    • Customizeddata-*attribute:These properties are commonly used in JavaScript operations, such as marking an element for quick selection by JS selectors, or storing a small amount of data related to the element.

      {% prevArchive prev %}
      {% if prev %}
        <a href="{{ prev.Link }}" class="prev-archive-link" data-archive-id="{{ prev.Id }}" data-category-id="{{ prev.CategoryId }}">{{ prev.Title }}</a>
      {% else %}
        <span class="no-prev-archive">已经是第一篇文章了</span>
      {% endif %}
      {% endprevArchive %}
      

      Bydata-archive-idanddata-category-idYour front-end script can easily retrieve the ID and category ID of the previous document, thus enabling more complex interactive features, such as displaying more information on hover.

Put these strategies into practice: an integrated example

Combining the above methods, a more comprehensive and customizable template fragment for the "previous article" link might look like this:

`twig

{% prevArchive prev %} {% if prev %}

<a href="{{ prev.Link }}"
   class="prev-archive-link highlight-on-hover"
   data-prev-archive-id="{{ prev.Id }}"
   data-prev-category-id="{{ prev.CategoryId }}"
   title

Related articles

`prevArchive` label outside the article detail page (such as the list page) whether it can still effectively obtain the previous document?

## Deep Dive into the `prevArchive` tag of Anqi CMS: The Mystery of the 'Previous' on List Pages As an experienced website operations expert, I am well aware that in daily content management, every tag and every function contains the potential to improve user experience and operational efficiency.AnQiCMS, with its simple and efficient features and SEO-friendly characteristics, has become a powerful assistant for many small and medium-sized enterprises and self-media operators.

2025-11-07

Can you get the views (Views) information of the previous document through the `prevArchive` tag?

## Deep Dive into AnQi CMS: Can the `prevArchive` tag retrieve the page views of the previous document?As an expert in website operations for many years, I know that every CMS system is crucial in terms of content management and data presentation.AnQiCMS (AnQiCMS) boasts its high efficiency and flexibility, and has been favored by many small and medium-sized enterprises and content operators.

2025-11-07

How to get the release (CreatedTime) or update time (UpdatedTime) of the previous document using the `prevArchive` tag?

## The clever use of `prevArchive` tag: Deeply explore the time mystery of the previous document in AnQi CMS As a senior website operation expert, I know that the timeliness and update frequency of content are crucial for the SEO performance and user experience of the website.In AnQiCMS (AnQiCMS), we often need to provide "Previous" and "Next" navigation on the article detail page, which is not only convenient for users to browse but also a good method to build internal links and improve page authority.Today, let's delve into the `prevArchive` tag

2025-11-07

In AnQi CMS, how can the `Id` field of the previous document be retrieved through the `prevArchive` tag?

As an old soldier who has been deeply involved in website operation for many years, I know that how to efficiently obtain and utilize content data in a content management system is crucial for improving user experience and website maintenance efficiency.AnQiCMS (AnQiCMS) boasts its concise and efficient features, providing many intuitive template tags to make content operation more flexible.Today, let's delve into a very practical scenario: how to retrieve the `Id` field of the previous document in AnQiCMS using the `prevArchive` tag.###

2025-11-07

The document for the previous archive tag is determined by what logic or sorting rules?

## Unveiling the Anqi CMS `prevArchive` tag: The intelligent sorting logic of the "Previous" document As an experienced website operations expert, I know that behind each CMS tag lies the potential to enhance user experience and SEO efficiency.AnQiCMS (AnQiCMS) is known for its efficiency and flexibility, and its template tag system is an extremely powerful tool for content operations.Today, let's delve into a seemingly simple but actually cleverly logical tag: `prevArchive`, and how it intelligently determines what we mean by 'previous document'

2025-11-07

Can the `prevArchive` tag retrieve the `Description` (summary) field of the previous document?

Sure, as an experienced website operations expert, I am happy to delve into the usage of the `prevArchive` tag in AnQi CMS and answer questions about obtaining the Description field of the document. --- ## Unlock Anqi CMS `prevArchive` tag: Easily get the summary of the previous document In daily website operations, we often need to provide users with a smooth reading experience and guide them to discover more related content. This includes

2025-11-07

How to format the `CreatedTime` or `UpdatedTime` obtained from the `prevArchive` tag into a readable date and time?

In website operation, the time of content release or update is an important part of conveying information to users.A clear and readable date-time format, which can not only improve the user experience but also enhance the professionalism and timeliness of the content.However, many content management systems typically use a string of timestamps that are difficult to understand intuitively.

2025-11-07

Does the `prevArchive` tag support getting custom field content from the backend of the previous document?

As an experienced website operation expert, I have a deep understanding of AnQiCMS (AnQiCMS) template tags and content operation strategies, and I am glad to give you a detailed explanation of the function of the `prevArchive` tag and discuss how to cleverly obtain the custom field content of the previous document. --- ### In-depth Analysis of AnQiCMS `prevArchive` Tag and Custom Field Retrieval Strategy In AnQiCMS template development, `prevArchive` and `nextArchive`

2025-11-07