前面我们学了一行代码搞定WordPress面包屑导航breadcrumb,现在wordpress文档中有一个简单实现的方法,适用于page页面,有二级分类的情况(Simple breadcrumb trail for pages, two levels deep.),随ytkah一起看看代码

echo '<div class="breadcrumb">';
    // If there is a parent, display the link.
    $parent_title = get_the_title( $post->post_parent ); 
    if ( $parent_title != the_title( ' ', ' ', false ) ) {
        echo '<a href="' . esc_url( get_permalink( $post->post_parent ) ) . '" alt="' . esc_attr( $parent_title ) . '">' . $parent_title . '</a> » ';
    } 
    // Then go on to the current page link.
    echo '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark" alt="' . esc_attr( the_title_attribute() ) . '">' . the_title() . '</a>';
echo '</div>';

  参考文档https://developer.wordpress.org/reference/functions/get_the_title/

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
相关资源
相似解决方案