How to build and display the navigation path of the current page in the website using the `breadcrumb` tag?

Calendar 👁️ 58

In website construction and operation, user experience (UX) is always at the core.When visitors delve into your website, a clear navigation path can effectively prevent them from getting lost and quickly understand their current position.This is the value of 'Breadcrumb Navigation'.It not only improves the user experience, but is also an important part of Search Engine Optimization (SEO), helping search engines understand the hierarchical structure of your website.

The AnQi CMS is well aware of this and therefore provides convenient and easy-to-usebreadcrumbtags, allowing you to easily build and display the navigation path of the current page of the user on the website

core functions and basic usage

breadcrumbThe tag automatically identifies the current page of the user and generates a series of clickable links based on the website's hierarchy (for example: Home > Category > Article).You do not need to manually write the navigation path for each page, Anqi CMS will intelligently complete this task.

UsebreadcrumbThe basic syntax of the tag is very intuitive:

{% breadcrumb crumbs %}
    <ul>
        {% for item in crumbs %}
            <li><a href="{{item.Link}}">{{item.Name}}</a></li>
        {% endfor %}
    </ul>
{% endbreadcrumb %}

In this code block:

  • {% breadcrumb crumbs %}: This is the start of the tag,crumbsIt is the variable name you specify for the breadcrumb navigation list.
  • {% for item in crumbs %}:crumbsA variable is a container that holds multiple navigation items(item) of an array. You can useforLoop through these navigation items.
  • {{item.Link}}: EachitemhasLinkProperty, which contains the URL address of the navigation item.
  • {{item.Name}}: EachitemAlso has aNameThe property includes the text displayed for navigation items.
  • {% endfor %}and{% endbreadcrumb %}: means loop andbreadcrumbEnd of tag.

In this way, Anqie CMS will output a standard HTML list structure, where each list item is a link pointing to the parent page on the user's current path.

Customize your breadcrumb navigation

breadcrumbTags also provide some parameters for you to customize flexibly according to your actual needs.

  1. Customize the homepage link text (indexparameters)By default, the first link of the breadcrumb navigation (i.e., the homepage) will be displayed as "Home". If you want to change this text, you can useindexparameters:

    {% breadcrumb crumbs with index="我的主页" %}
    {# ... 循环显示部分 ... #}
    {% endbreadcrumb %}
    

    This will display the starting point of the navigation path as "My Home Page" instead of "Home Page".

  2. Control the display of the current page title (titleparameters)On the detail page of the document or on the end page of a single page, the breadcrumb navigation usually displays the title of the current page.titleThe parameter provides three control methods:

    • title=true(Default): Display the full title of the current page.
    • title=falseDo not display the title of the current page. This may help simplify the visual effects in some designs.
    • title="自定义文本": You can replace the title of the current page with custom text. For example, on a product details page, you may want to display "Product Details" instead of the specific product name.
    {# 示例:不显示当前页面标题 #}
    {% breadcrumb crumbs with title=false %}
    {# ... 循环显示部分 ... #}
    {% endbreadcrumb %}
    
    {# 示例:将当前页面标题显示为“文章详情” #}
    {% breadcrumb crumbs with title="文章详情" %}
    {# ... 循环显示部分 ... #}
    {% endbreadcrumb %}
    
  3. Multi-site scenario (siteIdparameters)If you are using the AnQi CMS multi-site management feature and want to reference or display data from other sites in the breadcrumb navigation, you can usesiteIdParameters to specify the site ID. This is usually used for more complex cross-site content integration requirements.

Advanced examples and style suggestions

Combine these parameters to create breadcrumbs that better match the style of your website.In addition, don't forget to add styles for your breadcrumb navigation with CSS to make it more beautiful and readable on the page.

For example, one with a separator (such as>And customize the breadcrumb navigation of the homepage link:

<nav class="breadcrumb-nav">
    {% breadcrumb crumbs with index="网站首页" title=true %}
        <ol class="breadcrumb-list">
            {% for item in crumbs %}
                <li class="breadcrumb-item">
                    <a href="{{item.Link}}">{{item.Name}}</a>
                    {% if not forloop.Last %} {# 判断是否是最后一个链接,不是则添加分隔符 #}
                        <span class="separator"> &gt; </span>
                    {% endif %}
                </li>
            {% endfor %}
        </ol>
    {% endbreadcrumb %}
</nav>

{# 简单的 CSS 样式示例,您可以根据需要进行扩展 #}
<style>
    .breadcrumb-nav {
        font-size: 0.9em;
        padding: 10px 0;
        color: #666;
    }
    .breadcrumb-list {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex; /* 让列表项横向排列 */
        align-items: center;
    }
    .breadcrumb-item a {
        text-decoration: none;
        color: #337ab7;
    }
    .breadcrumb-item a:hover {
        text-decoration: underline;
    }
    .breadcrumb-item .separator {
        margin: 0 5px;
        color: #999;
    }
</style>

In this example, we utilize:forloop.LastTo determine whether it is the last element in the loop, thus adding a separator only after non-last links, avoiding extra>symbols.

Summary

breadcrumbThe tag is a powerful and practical feature in AnQi CMS, which helps you build clear and intuitive navigation paths on your website through automation and customization.Make good use of this tag, it can not only significantly improve the user's browsing experience, but also lay a solid foundation for better performance of your website in search engines.Mastering its usage will make your website operations more efficient and convenient.


Frequently Asked Questions (FAQ)

How to modify the display text of the 'Home' link in the breadcrumb navigation?You can use it toindexParameters to modify the display text of the 'Home' page. For example, if you want it to display as 'Website Homepage', you can use it in this way:{% breadcrumb crumbs with index="网站主页" %}...{% endbreadcrumb %}.

2. How can I make the breadcrumb navigation not display the specific title of the current page on the article or product detail page, or display a general title?You can usetitleParameters are controlled.

  • To completely hide the current page title, settitle=false:{% breadcrumb crumbs with title=false %}...{% endbreadcrumb %}.
  • To display a general title, such as “News Details”, settitle="新闻详情":{% breadcrumb crumbs with title="新闻详情" %}...{% endbreadcrumb %}.

3. My breadcrumb navigation has been implemented, but it looks quite ordinary without any visual separators or styles. How can I beautify it? breadcrumbThe tag mainly outputs an HTML structure (usually<ul><li><a>),it does not contain any style. You need to add style to these HTML elements through CSS. For example, you can add a separator between each navigation item<span> &gt; </span>As a separator, and set the color, font size, spacing, and other properties of the links and separators through CSS, just like the style examples provided in the article.

Related articles

How to retrieve and display the global configuration and SEO information of the website using `system`, `contact`, and `tdk` tags?

In the daily operation of AnQiCMS (AnQiCMS), accurately displaying global configuration information, contact information, and carefully optimized SEO elements on the website front end is the key to improving user experience and search engine visibility.Fortunately, AnQiCMS provides several intuitive and powerful template tags that allow users to easily access this important data.This article will delve into the three core tags `system`, `contact`, and `tdk`, helping you seamlessly integrate the background configuration into various pages of the website.Get the global configuration of the website

2025-11-08

How to format a timestamp with the `stampToDate` tag to display the date and time in a user-friendly manner?

In the daily content operation of Anqi CMS, we often need to present the original timestamp data such as publish time and update time in a way that is more accustomed to and easier to read for users.The original timestamp, such as `1609470335` such a pure number sequence, has no meaning to ordinary users.To solve this problem, AnQi CMS provides a very practical template tag——`stampToDate`, which can help us convert these numeric timestamps into a clear and user-friendly date and time display.###

2025-11-08

How to implement conditional display and loop display of dynamic content in AnQiCMS template using `if` and `for` tags?

In the Anqi CMS template world, `if` and `for` tags are the foundation for building dynamic and flexible pages.They give the template the ability to display content based on different data conditions, as well as the ability to efficiently loop through data sets, making your website content生动地呈现给visitors vividly.AnQi CMS adopts a template engine syntax similar to Django, making it easy for you, who is familiar with web development, to get started quickly, obtaining data through double curly braces `{{variable}}`, and using `{% tags %}` syntax for conditional judgment and loop control.### Use `if`

2025-11-08

How to generate and control the pagination display effect of the `pagination` tag?

In website operation, when the amount of content is large, how to efficiently and beautifully display these contents while ensuring that users can browse conveniently is the key to improving user experience.If you dump all the content on the same page, not only will it load slowly, but it will also deter visitors.At this moment, content pagination becomes particularly important. It breaks massive information into several pieces, which not only reduces the burden of page loading but also allows users to explore the content they are interested in step by step at their own pace.AnQiCMS provides a powerful and flexible `pagination` tag

2025-11-08

How does AnQiCMS support Markdown content editing and correctly render mathematical formulas and flowcharts on the front end?

AnQiCMS understands the desire of content creators for efficient and flexible editing tools.The new version introduces Markdown editor, greatly enhancing the convenience of content publishing.It is even more surprising that AnQiCMS not only supports basic Markdown syntax but also allows complex mathematical formulas and flowcharts to be elegantly presented on your website front-end through simple configuration.This is undoubtedly a powerful boost for websites that need to display professional knowledge, technical documentation, or educational content.### Enable Markdown Editing Feature First

2025-11-08

In AnQiCMS content settings, how to finely control the display of images (such as WebP, automatic compression, thumbnails)?

In website operation, images are important elements to attract users and convey information.However, unoptimized images may also be the culprit behind slow website loading, which can then affect user experience and search engine rankings.AnQi CMS knows the importance of image optimization and therefore provides a variety of fine-grained image control features to help you achieve a perfect balance between website performance and visual effects.### One, WebP: The intelligent choice for lightweight and fast image acceleration WebP, as a modern image format, typically has a file size 25-34% smaller than JPEG at the same visual quality

2025-11-08

How does AnQiCMS handle the display of external links in documents, does it automatically add the `nofollow` attribute?

In website operation, the management of external links is an important task, which not only relates to user experience, but also has a direct impact on search engine optimization (SEO).The use of the `nofollow` attribute can help website managers control the transmission of link weight more accurately, avoiding unnecessary risks.For users of AnQiCMS, understanding how the system handles external links in documents and whether it automatically adds the `nofollow` attribute is crucial for efficient website operation.AnQiCMS provides a clear and flexible strategy for handling external links

2025-11-08

How does AnQiCMS support multi-level menus and custom navigation categories to optimize the display of the website structure?

In website operations, a clear and effective navigation system is the key to user experience and search engine optimization.It not only guides visitors to find the information they need quickly, but also shows the structure and relevance of the website's content to search engines.AnQiCMS (AnQiCMS) has fully considered the actual needs of operators in website navigation settings, providing flexible multi-level menus and customizable navigation category functions to help users easily build a well-organized website structure.### Core Advantage: Flexibility and Structure The navigation feature of Anqi CMS aims to provide high customization and convenient management

2025-11-08