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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM