WordPress\\Bootstrap 4未正确构建面包屑

时间:2018-11-02 作者:Gregory Bologna

我的WordPress中有此代码functions.php 仅为页面创建面包屑。我做错了什么?谢谢

我想使用引导导航。问题是,短标记(The\\u title())将页面名称“Search”写在li标记之前,并在li标记中插入空引号。

function get_breadcrumb() {

    echo \'<nav aria-label="breadcrumb">\';
    echo \'<ol class="breadcrumb">\';

    if(!is_home() && !is_front_page()) {
        echo \'<li class="breadcrumb-item"><a href="\'.home_url().\'" rel="nofollow">Home</a></li>\';
        if (is_page()) {
            echo \'<li class="breadcrumb-item active" aria-current="page">"\'.the_title().\'"</li>\';
        }
    }
    echo \'</ol>\';
    echo \'</nav>\';
}

结果

<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="https://example.com" rel="nofollow">Home</a></li>Search
<li class="breadcrumb-item active" aria-current="page">""</li>
</ol>
</nav>

1 个回复
SO网友:Pat J

the_title() 默认情况下,回显标题。使用get_the_title() 相反

function get_breadcrumb() {

    echo \'<nav aria-label="breadcrumb">\';
    echo \'<ol class="breadcrumb">\';

    if(!is_home() && !is_front_page()) {
        echo \'<li class="breadcrumb-item"><a href="\'.home_url().\'" rel="nofollow">Home</a></li>\';
        if (is_page()) {
            echo \'<li class="breadcrumb-item active" aria-current="page">"\'.get_the_title().\'"</li>\';
        }
    }
    echo \'</ol>\';
    echo \'</nav>\';
}

结束

相关推荐

如何创建4列和2列Twitter-Bootstrap相结合的WordPress循环?

我想根据4列(桌面视图)、2列(mobile view 768px)和1列(mobile view 425px)的组合显示帖子。我在下面找到了很棒的代码:<?php $paged = ( get_query_var(\'paged\') ) ? get_query_var(\'paged\') : 1; $args=array( \'post_type\' => \'post\',