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/

posted @ 2019-08-05 16:14  ytkah  阅读(1578)  评论(0编辑  收藏  举报
IPO发家故事 网址导航 gg N / G Sitemap

部分内容来源于网络,如有版权问题请联系删除