How to automatically generate the breadcrumb navigation of the page in the AnQiCMS template using the `breadcrumb` tag?

Calendar 👁️ 64

When browsing websites, we often notice a series of path information at the top or bottom of the page, which clearly indicates our current location, such as "Home > Category > Article Title."}This is what we commonly call Breadcrumb Navigation.It not only helps users better understand the website structure and improve the browsing experience, but also has an indispensable value for search engine optimization (SEO).

Why is breadcrumb navigation important?

For users, breadcrumb navigation is like a mini-map, allowing them to always understand their journey on the website and easily backtrack to the upper-level page, avoiding getting lost.Especially when the content hierarchy of a website is deep, the breadcrumb navigation becomes more prominent, providing a direct and convenient return path, greatly enhancing the user experience.

From the perspective of search engine optimization, breadcrumb navigation also plays an important role.It provides clear clues to search engine spiders about the website structure, helping to capture and understand the logical relationship between pages.At the same time, the links in the breadcrumb navigation are internal links, which can effectively pass on page authority, optimize the internal link structure of the website, and thereby help improve the keyword ranking of the page.

The convenience of automatically generating breadcrumb navigation in Anqi CMS

AnQi CMS was designed with full consideration of website structure and user experience, therefore, it built-in very convenient mechanisms to automatically generate breadcrumb navigation, without complex configuration or manual coding.By using a concise template tag, the system can intelligently judge the hierarchical relationship of the current page type (whether it is an article detail page, a category list page, or a single page) and automatically build a complete breadcrumb navigation path.This not only saves us a lot of time in development and maintenance, but also ensures the accuracy and consistency of navigation.

How to usebreadcrumbTag

The core of automatically generating breadcrumb navigation in Anqi CMS's template system isbreadcrumbLabel. Its usage is very intuitive, following the Django template engine syntax rules, even friends who are new to template development can quickly get started.

We usually place the breadcrumb navigation code snippet in a separate template file, for examplepartial/breadcrumb.htmlThen, in the page where the breadcrumb needs to be displayed throughincludeLabel it. The advantage of doing this is that it is convenient for maintenance and reuse.

Next isbreadcrumbBasic usage of the tag:

{# 假设这个代码片段在 partial/breadcrumb.html 文件中 #}
<div>
    {% breadcrumb crumbs %}
    <ul>
        {% for item in crumbs %}
            <li><a href="{{item.Link}}">{{item.Name}}</a></li>
        {% endfor %}
    </ul>
    {% endbreadcrumb %}
</div>

In this code block,{% breadcrumb crumbs %}Tell AnQi CMS to retrieve the breadcrumb navigation data for the current page and store it in a namedcrumbs.crumbsis an array object, each element representing a node in the navigation path.

Next, we use{% for item in crumbs %}Loop throughcrumbsarray. In each iteration,itemthe variable will represent the current navigation node. We can use{{item.Name}}Get the display name of the node through{{item.Link}}Get the link address of the node. This way, the system will automatically render a series of navigation texts with links.

breadcrumbLabel parameters and customization

breadcrumbThe tag also provides several practical parameters, helping us to customize more finely according to our actual needs:

  1. indexParameter: Customize the home page nameBy default, the starting point of the breadcrumb navigation is "Home Page". If you want to change this name to "My Blog", "Website Homepage", or other text, you can useindexSet the parameters.

    {# 将首页名称设置为“我的主页” #}
    {% breadcrumb crumbs with index="我的主页" %}
    
  2. titleParameter: Controls the display of the current page titleIn some cases, you may not want the last element of the breadcrumb navigation (i.e., the title of the current page) to have a link, or you may want it to display different text.titleParameters can help us meet these needs.

    • title=true(Default): Displays the full document title and acts as the last non-clickable element.
    • title=false: Do not display the title of the current page.
    • title="自定义文字": Display the text you specify as the current page title instead of the actual page title.
    {# 不显示当前页面的标题 #}
    {% breadcrumb crumbs with title=false %}
    
    {# 将当前页面的标题显示为“文章详情” #}
    {% breadcrumb crumbs with title="文章详情" %}
    
  3. siteIdParameter: Data call under multiple sites (usually no need to set)If you are using the multi-site management feature of Anqi CMS and need to call data from another site's template on a certain site, you can usesiteIdThe parameter specifies the target site. However, in most single-site operation scenarios, this parameter does not need to be set, as the system will automatically identify the current site.

Actual application example

Combining these parameters with the general HTML structure, we can build a more functional and flexible breadcrumb navigation. The following example shows how to useforloop.LastTo determine whether it is the last navigation item and add a different style to it (usually the last item does not need a link):

<nav aria-label="breadcrumb" class="my-3">
    <ol class="breadcrumb">
        {# 使用 index 参数定制首页名称,title 参数控制当前页面标题的显示 #}
        {% breadcrumb crumbs with index="安企CMS主页" title=true %}
        {% for item in crumbs %}
            {% if forloop.Last %}
                {# 最后一个导航项通常是当前页面,不加链接,并可能添加 active 类 #}
                <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>

In this example, we used HTML5's<nav>and<ol>Label, and supplemented witharia-labelandaria-currentProperties to enhance accessibility. Throughforloop.LastWe cleverly mark the last breadcrumb item (current page) asactiveStatus, and removed its link, which conforms to common design patterns.

Visible, Anqi CMS through simple and intuitive.breadcrumbThe tag greatly simplifies the implementation process of breadcrumb navigation, allowing us to focus on content and website strategy instead of繁琐的底层代码.

Frequently Asked Questions (FAQ)

Q1: Why is my breadcrumb navigation not displaying the title of the current article? A1: This is usually becausebreadcrumblabel'stitlethe parameter is set tofalseOr another custom value. Please check the template code in{% breadcrumb crumbs with ... %}this line, make suretitlethe parameters are either omitted (defaulttrue), either explicitly set totrue.

Q2: How do I change the text of the "Home" in the breadcrumb navigation? A2: You can set it throughbreadcrumblabel'sindexParameters can be easily implemented. For example, if you want to change 'Home' to 'Website Home Page', you can modify it like this: {% breadcrumb crumbs with index="网站主页" %}.

Q3: Why is my breadcrumb navigation path generation incorrect, or why are some pages not displaying breadcrumbs? A3: This may have several reasons. First, make sure that the page type (article, category, single page, etc.) has a clear hierarchy setting in the Anqi CMS backend.Secondly, the configuration of pseudo-static rules may also affect the correct generation of breadcrumbs, please check whether the pseudo-static rules in "Function Management" are configured correctly.If there is a problem on a newly created page, it may be necessary to ensure that the page has been published and has a clear category or parent relationship.

Related articles

How to use the `archiveFilters` tag in AnQiCMS to achieve combined filtering of document parameters?

## Mastering AnQiCMS: The Art of Using `archiveFilters` Tag for Document Parameter Combination Filtering It is crucial to provide users with accurate and efficient content search experience in content operation.Imagine if your website has a rich variety of content, but users find it difficult to quickly find the information they need. This will undoubtedly greatly affect user experience and the conversion rate of the website.

2025-11-08

How to enable and use the captcha feature of the留言表单in AnQiCMS?

The website guestbook is a good place to interact with visitors, which brings the website closer to the users.However, without proper protection, the message board will soon be overwhelmed by various spam, malicious submissions, and even automated scripts, which not only affects the cleanliness of the website but may also consume server resources and even damage the reputation of the website.Fortunately, AnQiCMS provides a simple and effective solution: the captcha feature.

2025-11-08

How to display comment content and user status for the `commentList` label in AnQiCMS?

Build a highly interactive website in AnQiCMS, the comment function is undoubtedly the key to increasing user engagement.The `commentList` tag is a great tool provided by AnQiCMS for this purpose, it can help website developers and operators flexibly display comment content, and clearly present the status of commenters, allowing visitors to grasp the dynamics of the comment area at a glance.### Core Feature Overview: Basic Usage of `commentList` Tag The `commentList` tag is mainly used to retrieve the comment list of a specified document

2025-11-08

How to create a multi-level category navigation and display its subcategories or related documents in AnQiCMS template?

Build flexible multi-level category navigation and content display in AnQiCMS template Effective organization of website content is crucial for providing a good user experience and improving search engine visibility.Whether it is a corporate website, product display, or self-media blog, a clear multi-level classification navigation can help users quickly find the information they need and is also conducive to search engines understanding the structure of the website.AnQiCMS as an efficient and customizable content management system provides flexible template tags, allowing us to easily implement complex multi-level classification navigation and content display. Next

2025-11-08

How to flexibly control the display quantity and style of pagination page numbers with the `pagination` tag of AnQiCMS?

When managing a content-rich website, an efficient page navigation system is crucial for enhancing user experience and search engine optimization (SEO).AnQi CMS knows this, its built-in `pagination` tag provides us with detailed control, making the website page number display both flexible and beautiful.This article will guide you to understand how to use the `pagination` tag, flexibly control the display quantity and style of pagination page numbers.

2025-11-08

How to format timestamp output to date or time string in AnQiCMS template?

In website operation, the date and time information of content publication, update, and other aspects are crucial for user experience and content management.AnQiCMS as a rich-featured content management system, provides flexible template tags, allowing users to easily format the timestamp data stored in the background into various easily readable date or time strings to meet different display requirements.

2025-11-08

How do the `urlize` and `urlizetrunc` filters handle URL links in the AnQiCMS template?

In website operation, we often need to embed various links in the content, whether they point to internal resources or external references.Manually converting plain text links into clickable hyperlinks is not only inefficient but also prone to errors.It is more important that standardized link handling is crucial for search engine optimization (SEO) and user experience.

2025-11-08

How to use the `length` filter to get the length of a string, array, or key-value pair in AnQiCMS templates?

In AnQiCMS template development, we often need to process and judge the data displayed on the page.Among them, getting the length of a string, array, or key-value pair is a very basic and practical operation.The AnQiCMS template engine provides the `length` filter, making this task simple and intuitive. ### Understanding the `length` filter: A tool for getting data length The `length` filter, as the name implies, is used to get the 'length' of the data.

2025-11-08