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

Calendar 👁️ 71

In website operation, Breadcrumb Navigation is an important element for improving user experience and website structure clarity.It not only helps visitors quickly understand the position of the current page in the website hierarchy, but also effectively assists search engines in understanding the relationships between website content, playing a positive role in SEO optimization.For AnQiCMS users, building and displaying breadcrumb navigation is a very convenient operation, thanks to the powerful template tags built into AnQiCMS.

Understand AnQiCMS'breadcrumbTag

AnQiCMS provides a dedicated tool for generating breadcrumb navigationbreadcrumbThe tag is designed to simplify the development process, allowing content operators and template developers to easily integrate this feature into the page.breadcrumbThe tag will automatically generate a navigation path list based on the current page's URL path and content hierarchy (such as categories, articles, single pages, etc.).

UsebreadcrumbThe basic structure of the tag is as follows:

{% breadcrumb crumbs %}
    {# 在这里循环输出面包屑导航的每一项 #}
{% endbreadcrumb %}

Here, crumbsIt is an array object generated by AnQiCMS, which includes each link in the breadcrumb navigation from the homepage to the current page. Developers need to go throughforLoop through thiscrumbsAn array to render each link on the navigation path sequentially.

Inforthe loop,crumbseach element of the arrayitemBoth provide two core properties for us to use:

  • item.Name: Represents the display name of a navigation item, such as 'Home', 'News Center', 'Article Title', etc.
  • item.Link: Represents the URL link corresponding to the navigation item, which will jump to the page when clicked.

Therefore, a typical breadcrumb navigation rendering code snippet would look like this:

{% breadcrumb crumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            {% for item in crumbs %}
                <li class="breadcrumb-item{% if forloop.Last %} active{% endif %}">
                    {% if forloop.Last %}
                        {{ item.Name }}
                    {% else %}
                        <a href="{{ item.Link }}">{{ item.Name }}</a>
                    {% endif %}
                </li>
            {% endfor %}
        </ol>
    </nav>
{% endbreadcrumb %}

In this example, we used the HTML5<nav>and<ol>tag to enhance semanticization, and throughforloop.LastDetermine if it is the last navigation item on the current page. If it is the last one, we usually only display text without adding a link, and addactivea class name to distinguish the style.

breadcrumbThe core parameters of the tag

breadcrumbThe tag also provides several practical parameters to help us better control the display behavior of breadcrumb navigation:

  1. indexParameter: Customize the home page nameBy default, the first link of the breadcrumb navigation (usually the root directory of the website) is displayed as 'Home'. ThroughindexParameter, we can easily change it to other text, such as "my blog" or "homepage".

    Usage example:

    {% breadcrumb crumbs with index="我的网站" %}
        {# ... 遍历 crumbs 数组 ... #}
    {% endbreadcrumb %}
    

    In this way, the first link of the breadcrumb navigation will display as "my website".

  2. titleParameter: Controls the display of the current page titleIn some cases, we may not want the last item of the breadcrumb navigation (i.e., the title of the current page) to be too long, or we may want it to be displayed as more concise text.titleThe parameter can help us achieve this.

    • title=true(Default): Display the full title of the current page.
    • title=false: Do not display the title of the current page, the breadcrumb navigation will stop at the parent page of the current page.
    • title="自定义文字": Replace the title of the current page with the specified custom text.

    Usage example:

    {# 示例一:不显示当前页面的标题 #}
    {% breadcrumb crumbs with title=false %}
        {# ... 遍历 crumbs 数组 ... #}
    {% endbreadcrumb %}
    
    {# 示例二:将当前页面标题显示为“详情内容” #}
    {% breadcrumb crumbs with title="详情内容" %}
        {# ... 遍历 crumbs 数组 ... #}
    {% endbreadcrumb %}
    
  3. siteIdParameter: Data call in multi-site scenarioFor users of AnQiCMS multi-site management feature,siteIdParameters are allowed to call data from other sites in the current site template. Usually, users do not need to set this parameter,breadcrumbThe tag automatically retrieves data from the current site. It is only needed for specific advanced requirements, such as displaying another site's breadcrumb path within a site.siteId.

    Usage example:

    {# 假设需要获取ID为2的站点的面包屑 #}
    {% breadcrumb crumbs with siteId="2" %}
        {# ... 遍历 crumbs 数组 ... #}
    {% endbreadcrumb %}
    

Build a complete and customizable breadcrumb navigation in practice

Combining these parameters, we can build a comprehensive and flexible customizable breadcrumb navigation. The following code demonstrates a common application scenario, considering the display of the home page name, the current page title, and using semantic HTML structure:

<div class="container my-3">
    {% breadcrumb crumbs with index="网站首页" title=true %}
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb bg-light p-2 rounded">
                {% for item in crumbs %}
                    <li class="breadcrumb-item{% if forloop.Last %} active{% endif %}">
                        {% if forloop.Last %}
                            <span class="text-secondary">{{ item.Name }}</span>
                        {% else %}
                            <a href="{{ item.Link }}" class="text-decoration-none text-primary">{{ item.Name }}</a>
                        {% endif %}
                    </li>
                    {% if not forloop.Last %}
                        <span class="breadcrumb-separator mx-2">/</span>
                    {% endif %}
                {% endfor %}
            </ol>
        </nav>
    {% endbreadcrumb %}
</div>

In this example, we not only set the home page name to "website home page", but also ensured that the current page (forloop.Last) does not have a link in its name and used<span>Label wrapping for easy CSS styling control. At the same time, by adding separators<span>Labels make the visual effect of breadcrumb navigation clearer.

Summary

AnQiCMS'breadcrumbTags provide a直观而强大的方式 to build and display the breadcrumb navigation of a website. By using flexiblyindexandtitleWith parameters, we can easily customize the display content and form of navigation, thereby greatly enhancing the user experience and SEO performance of the website without increasing the amount of complex code. For content operators and developers who want to have a clear navigation structure on the website, masteringbreadcrumbLabels are an essential skill.


Frequently Asked Questions (FAQ)

Q1: Why is my breadcrumb navigation not displaying the title of the current page?A1: This is likely becausebreadcrumblabel'stitlethe parameter is set tofalseOr other custom text has been specified. Please check your template code.{% breadcrumb ... %}Within the tag.titleSet the parameter settings, make sure it is set totrueTo display the complete title of the current page or set it to the custom text you expect.

Q2: How can I make each item in the breadcrumb navigation display an arrow or other separator?A2: The separator in breadcrumb navigation is usually implemented through CSS styles, or as shown in the previous example, by manually adding a separator character (such asforin a loop, manually adding a separator character (such as/or>)的<span>Label. For example, you can insert one after each<li>element (except the last one)<span>/</span>and then use CSS to position and style it.

Q3: How to modify the display text of 'Home' in the breadcrumb navigation?A3: You can usebreadcrumblabel'sindexParameters can easily modify the display text of the 'Home' page. For example, if you want to display 'Home' as 'Website Homepage', you can set it like this in the label:{% breadcrumb crumbs with index="网站主页" %}.

Related articles

How to use the `if` tag in AnQiCMS templates for conditional judgment to control content display?

When managing content in AnQi CMS, we often need to display different information based on different situations.For example, a blog post may have a thumbnail, while another does not; or a module may only display under certain conditions.At this time, flexibly using the conditional judgment in the template, that is, the `if` tag, can help us achieve these dynamicized content display needs.The AnQi CMS template engine supports syntax similar to Django, where the `if` tag is the core tool for conditional judgments.

2025-11-09

How to prevent content scraping on the front end in AnQiCMS, such as displaying watermarks or interference codes?

Protect Originality: AnQiCMS intelligent strategy for front-end content collection prevention In the era of explosive Internet content, the value of original content is becoming more and more prominent, but it also faces the risk of malicious collection.The hard work we put into writing and carefully designed images can be stolen in an instant by others, not only infringing on the creators' labor成果, but also potentially affecting the website's SEO performance and brand image.How can we effectively protect our digital assets?AnQiCMS (AnQiCMS) provides a very practical built-in solution to this issue

2025-11-09

How to automatically convert plain text URLs of articles in the AnQiCMS template to clickable hyperlinks?

In daily website content operations, we often need to mention some external links or URLs in articles, product descriptions, or single-page content.If these URLs appear only in plain text, visitors will not be able to click and jump directly, which will undoubtedly affect the user experience, and may even cause some important information to be ignored.AnQiCMS as a powerful content management system, provides a simple and efficient way to solve this problem, making your content more vivid and interactive.AnQiCMS uses a template engine syntax similar to Django

2025-11-09

How to implement multi-condition filtering display on the article list page with the `archiveFilters` tag of AnQiCMS?

It is crucial to provide users with a convenient and accurate content search experience in website operation.As the content of the website becomes richer, simple classification or keyword search is often not enough to meet the personalized needs of users.At this time, the multi-condition filtering function on the article list page is particularly important.For AnQiCMS users,巧妙利用 `archiveFilters` tag can easily achieve this goal, making your article list page instantly possess powerful filtering capabilities.

2025-11-09

How to customize parameters in the AnQiCMS backend and display them in the front-end template?

During the operation of a website, we often encounter such needs: standard content fields (such as title, content, publication time) can no longer meet the needs of personalized display.For example, a product detail page may need to display "production dateAnQiCMS as a flexible enterprise-level content management system fully considers these customized needs.

2025-11-09

How to implement scheduled publishing of articles in AnQiCMS to ensure that content is visible on the front page at specified times?

As a content operator, we know that in the age of information explosion, the timing of content release often determines its dissemination effect.In order to coordinate with market activities, maintain a stable update frequency, or publish important announcements at specific times, a function that can accurately control the publication time is indispensable.AnQiCMS (AnQi Content Management System) is well-versed in this, providing us with a simple and powerful scheduling mechanism to ensure that every meticulously prepared article is presented to the reader at the most appropriate time.Use AnQiCMS for timed publishing

2025-11-09

How to iterate over an array or slice in AnQiCMS template and loop through its elements?

In the AnQi CMS template world, dynamically displaying content is the key to building an active and feature-rich website.Whether it is an article list, product display, navigation menu, or image gallery, we need a mechanism to traverse the data set and display each element on the page.Fortunately, the template engine of Anqi CMS provides an intuitive and easy-to-use loop structure, allowing us to easily achieve this goal.

2025-11-09

How to define variables and display their values in AnQiCMS templates?

In AnQiCMS templates, we often need to handle various data, whether it is the name of the website, the title of the article, or the product details, these dynamic contents all need to be carried and displayed through variables.Understanding how to define and display variables in templates is the core of AnQiCMS template development.AnQiCMS adopts a syntax similar to the Django template engine, making the use of variables intuitive and easy to pick up.In the template file (usually in `.html` format, stored in the `/template` directory)

2025-11-09