wordpress面包屑导航简单实现

  前面我们学了一行代码搞定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/

原文地址:https://www.cnblogs.com/ytkah/p/11303666.html