【问题标题】:How to change the last breadcrumb item name in wordpress using Breadcrumb navXT?如何使用 Breadcrumb navXT 更改 wordpress 中最后一个面包屑项目名称?
【发布时间】:2020-07-30 08:28:14
【问题描述】:

我有一个“主页 | 新列表 | 详细帖子新”的面包屑,其中“详细帖子新”页面是固定的,我只在那里传递帖子,我该如何更改“新帖子”的名称示例文章的:“首页 | 新列表 | 标题帖子 1”

Home | List New | Detail Post New

随着每篇文章的变化

Home | List New | Title Post 1

我的代码

    <nav aria-label="breadcrumb" class="wrap-breadcrumb">
        <div class="container">
            <div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
                <?php if(function_exists('bcn_display'))
                {
                    bcn_display();
                }?>
            </div>
        </div>
    </nav>

【问题讨论】:

    标签: php wordpress breadcrumbs


    【解决方案1】:

    我遇到了同样的问题。我用这个“拐杖”解决了它。

    1. 我使用“PODS”插件创建了新的自定义字段。我在该字段中添加了新的面包屑标题。

    2. 我使用了 'bcn_breadcrumb_title' 钩子并获得了帖子 'ID'。

    3. 如果我的帖子“ID”与面包屑“ID”匹配,则标题会更改。

    (对不起我的英语)

    add_filter('bcn_breadcrumb_title', 'my_breadcrumb_title_swapper', 3, 10);
    
    function my_breadcrumb_title_swapper($title, $type, $id)
    {
    
      $post = get_post();
      $post_id = $post->ID;
    
      if ( $post_id == $id )
      {
        if ( get_post_meta( $post_id, 'last_breadcrump_title', true) )
        {
          $title = get_post_meta( $post_id, 'last_breadcrump_title', true);
        }
      }
    
      return $title;
      return $type;
      return $id;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-25
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多