How to generate `breadcrumb` tags?

Calendar 👁️ 64

On a day when the content of websites becomes increasingly rich, users often need to navigate between different pages on the website.To help visitors understand their current location and provide a convenient return path, breadcrumb navigation (Breadcrumb Navigation) has emerged.It's like a path indicator on a map, making it clear for users to know 'Where I came from and where I'm going'.

AnQiCMS fully understands the importance of breadcrumb navigation for user experience and website structure, therefore it has built-in special tags in the template.breadcrumbLabels, allowing website developers and operators to easily generate dynamic and flexible breadcrumb navigation. Next, we will learn in detail how to use this convenient label.

The basic method for generating breadcrumb navigation

In the AnQiCMS template, generating breadcrumb navigation is very intuitive. You can usebreadcrumbTag to get the complete path information of the current page. It is usually used withforLoop to iterate over each link in the path.

For example, a basic breadcrumb navigation code snippet might look like this:

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

In this code block,{% breadcrumb crumbs %}and{% endbreadcrumb %}It encapsulates the logic to generate breadcrumbs.crumbsis an array object representing all levels from the homepage to the current page. We traverse this array,{% for item in crumbs %}traverse this array,item.NameIndicates the display name of each level (such as "Home", "Product Center", "Some Product Name"),item.LinkRepresents the corresponding link address of the level. Through judgmentforloop.LastCan distinguish whether the current page is the last item in the breadcrumb path, thereby giving it different styles or behaviors (such as the last item being non-clickable plain text).

Flexibly configure the breadcrumb navigation parameters

breadcrumbTags are not only simple to use but also provide several practical parameters to help you customize the website according to your specific needs.

  1. titleParameter: Control the display of the end title titleParameter used to control the display style of the last item in the breadcrumb navigation (usually the title of the current page)

    • When you settitle=trueWhen this is the default value, the breadcrumb will display the full document or page title as the last item.
    • If you wish to not display the current page title, you can set it totitle=false.
    • Further, you can also settitleto a custom string, for exampletitle="文章详情"So the last item of the breadcrumb will be displayed with the text you specify, not the specific title of the page.
  2. indexParameter: Customize the home page nameThe starting point of breadcrumb navigation is usually "Home", but sometimes you may want to display it as a custom name like "My Blog", "Company Website", etc.indexThe parameter can meet this need.

    • For example, useindex="我的博客"You can change the starting item of the breadcrumb from the default "Home" to "My Blog".
  3. siteIdParameter: Data call in multi-site environmentFor users who use the AnQiCMS multi-site management feature,siteIdthe parameter allows you to specify from which site to obtain the breadcrumb data.

    • In most cases, if you are running a single site or want the breadcrumbs to reflect the current site path, you do not need to fill in this parameter. It will automatically retrieve the path information of the current site.

Example of a comprehensive: Building a diverse breadcrumb navigation

After understanding the parameters, we can try to build a more flexible breadcrumb navigation.

Assuming we want:

  • The homepage should display as "My Homepage".
  • On the article detail page, the last breadcrumb item is unifiedly displayed as
  • Other category pages display the category name normally.
<div>
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            {% breadcrumb crumbs with index="我的主页" title="详情内容" %}
            {% for item in crumbs %}
                {% if forloop.Last %}
                    <li class="breadcrumb-item active" aria-current="page">{{item.Name}}</li>
                {% else %}
                    <li class="breadcrumb-item"><a href="{{item.Link}}">{{item.Name}}</a></li>
                {% endif %}
            {% endfor %}
            {% endbreadcrumb %}
        </ol>
    </nav>
</div>

By such settings, AnQiCMS will intelligently generate breadcrumb paths based on the current page type, display "Details content" uniformly at the end of the article detail page, and show "My homepage" on the homepage.

Some suggestions in practice.

In the process of template creation, in order to improve code reusability and maintainability, we usually store the breadcrumb navigation code snippet separately inpartialin the directory, for examplepartial/breadcrumb.html. Then, through the page where breadcrumbs need to be displayed,{% include "partial/breadcrumb.html" %}to refer to. In this way, when the logic or style of breadcrumbs needs to be adjusted, it is only necessary to modify one file.

Breadcrumbs navigation not only helps improve user experience, but also clearly shows the structural hierarchy of the website to search engines from the perspective of SEO, which is helpful to improve the crawling and ranking of the website. Through AnQiCMS'sbreadcrumbLabel, you can easily implement a beautiful and practical breadcrumb navigation system.


Frequently Asked Questions (FAQ)

Q1: Why is the last item of the breadcrumb navigation on my article detail page not displaying the article title, but other text or not displaying at all?A1: This is likely becausebreadcrumblabel'stitleThe parameter is set to a specific value orfalse. Please check the line in your template code{% breadcrumb crumbs %}If it containstitle="自定义文字"ortitle=falseit will override the default behavior of displaying the article title. To display the article title, you can removetitlethe parameter or set it totitle=true.

Q2: How to change the display text of 'Home' in the breadcrumb navigation?A2: You can change the display text of 'Home' by usingbreadcrumblabel'sindexparameters. For example, you can add to the tag.index="我的主页"orindex="网站首页"You can replace the default 'Home' with the text you specify.

Q3: The style of the breadcrumb navigation does not look very beautiful, does AnQiCMS provide style settings?A3: AnQiCMS'breadcrumbThe tag is mainly responsible for generating the breadcrumb navigation data structure (i.e., path names and links), and outputs it as an HTML skeleton.As for aesthetic style, it usually belongs to the design scope of front-end (CSS).You need to be in the CSS file of the website, targeting the HTML elements of the breadcrumb navigation (such as<ol class="breadcrumb">and<li class="breadcrumb-item">Write the corresponding style rules to achieve the expected visual effects. You can put the breadcrumb code snippet inpartial/the directory for easy management of styles and structure.

Related articles

How to use the `navList` tag to create the main navigation menu of a website and support two-level dropdown display?

The main navigation menu of the website is an important entry for users to understand the content and structure of the website.The Anqi CMS provides a powerful and flexible `navList` tag, which helps us easily create and manage multi-level dropdown navigation menus, thus enhancing the user experience and clarity of the information architecture of the website. ### Step 1: Configure the navigation menu in the AnQi CMS backend Before starting to write template code, we need to set up the structure of the navigation menu in the AnQi CMS backend management system. 1.

2025-11-08

How to display all related document lists under a specific `tagDataList` tag and support pagination?

In AnQi CMS' daily content management, we often need to organize and display website content more flexibly.In addition to the traditional classification system, tags (Tag) provide us with another powerful way to associate content.It can aggregate documents from different categories but with similar themes, providing users with a more focused browsing experience.Today, let's delve into a very practical template tag in Anqi CMS, `tagDataList`, and see how it helps us display all related document lists under a specific tag and easily implement pagination.

2025-11-08

How to effectively manage and display single-page content on a website using `pageList` and `pageDetail` tags?

In website operation, single-page content plays an indispensable role, it usually carries important information such as "About Us", "Contact Us", "Terms of Service", "Privacy Policy", etc., which needs to be clearly displayed and also requires convenient management.AnQiCMS provides the powerful template tags `pageList` and `pageDetail`, which help us efficiently manage and display these single-page content.

2025-11-08

How to retrieve and display the name, description, Banner image, and thumbnail of a specific category using the `categoryDetail` tag?

In AnQiCMS template creation, we often need to retrieve and display detailed information about specific categories, such as the name, description, and even preset Banner images and thumbnails.`categoryDetail` tag is born for this, it helps us easily extract this data from the database and flexibly display it on the website front end.

2025-11-08

How to customize the content model of Anqi CMS to achieve diversified content display?

When building website content, we often find that various types of information have unique display requirements.A news article may require a title, author, publication date, and main content; a product introduction may cover name, model, price, inventory, and detailed parameters; and a case study may focus more on project name, client, solution, and result images.Traditional CMS systems often provide fixed and unchangeable content publication templates, which make it difficult to deal with diverse business scenarios and lack flexibility.

2025-11-08

How to set a unique display layout for different types of articles (such as news, products)?

In website operation, content is not just information itself, but also the way it is presented is equally important.Setting unique display layouts for different types of content (such as news, product introductions) can greatly enhance user experience, strengthen brand image, and even have a positive impact on search engine optimization (SEO).AnQiCMS (AnQiCMS) provides very flexible and powerful features in this aspect, allowing you to easily create exclusive visual styles for various types of content.

2025-11-08

How does the multilingual support of Anqi CMS affect the display and switching of front-end content?

AnQiCMS provides powerful multilingual support capabilities, which is crucial for websites that want to expand into global markets and provide localized content experiences for users of different languages.It not only affects the way the front-end content of the website is presented, but also provides users with a smooth language switching experience.Understanding how it works can help us better plan and operate multilingual websites.

2025-11-08

How does static URL affect the display results of a website in search engines?

Have you ever been troubled by a long string of question marks, equals signs, and numbers in the website address bar?Such a URL is not only visually unattractive, but may also subtly affect your website's performance in search engines.The so-called 'pseudo-static URL' we often talk about is used to solve this problem.Then, what impact do these static URLs have on the display results of a website in search engines?Let's delve into it together.What is a static URL and why is it important?

2025-11-08