サポート » 使い方全般 » パン屑リストの親カテゴリーを非表示にしたい

  • こんにちは。

    サイトにパン屑リストにつきましてご質問させてくださいませ。
    プラグインを使わずに、Play Under Worldさまの
    http://blog.playunderworld.com/web/how-to-breadcrumbs-in-wordpress/を
    使用させて頂き設置してみました。

    達成したい事案として、
    各記事の子カテゴリー名のみを表示でき
    親カテゴリーを非表示にしたいのです。

    現在は、「トップページ > 親カテゴリー名(リンク有) > 子カテゴリー名(リンク有) > 記事名」となっているのですが、これを
    「トップページ > 子カテゴリー名(リンク有) > 記事名」としたいのです。

    いろいろ調べて試してはみたのですが
    技術不足故、うまくいきません。。。
    どなたかお力添えをいただけませんでしょうか。

    どうぞよろしくお願いいたします。

    以下、function.phpに記載しています
    <?php
    function get_breadcrumbs(){
    global $wp_query;

    if ( !is_home() ){

    // Start the UL
    echo ”;
    // Add the Home link
    echo ‘‘. get_bloginfo(‘name’) .’‘;

    if ( is_category() )
    {
    $catTitle = single_cat_title( “”, true );
    $cat = get_cat_ID( $catTitle );
    echo ” > “. get_category_parents( $cat, true, ” ” ) .””;
    }
    elseif ( is_archive() && !is_category() )
    {
    echo “> Archives”;
    }
    elseif ( is_search() ) {

    echo “> Search Results”;
    }
    elseif ( is_404() )
    {
    echo “> 404 Not Found<“;
    }
    elseif ( is_single() )
    {
    $category = get_the_category();
    $category_id = get_cat_ID( $category[0]->cat_name );

    echo ‘ > ‘. get_category_parents( $category_id, true, ” > ” );
    echo the_title(”,”, FALSE) .””;
    }
    elseif ( is_page() )
    {
    $post = $wp_query->get_queried_object();

    if ( $post->post_parent == 0 ){

    echo “> “.the_title(”,”, FALSE).””;

    } else {
    $title = the_title(”,”, FALSE);
    $ancestors = array_reverse( get_post_ancestors( $post->ID ) );
    array_push($ancestors, $post->ID);

    foreach ( $ancestors as $ancestor ){
    if( $ancestor != end($ancestors) ){
    echo ‘> ‘. strip_tags( apply_filters( ‘single_post_title’, get_the_title( $ancestor ) ) ) .’‘;
    } else {
    echo ‘> ‘. strip_tags( apply_filters( ‘single_post_title’, get_the_title( $ancestor ) ) ) .”;
    }
    }
    }
    }

    // End the UL
    echo “”;
    }
    }
    ?>
    <?php
    function get_breadcrumbs2(){
    global $wp_query;

    if ( !is_home() ){

    // Start the UL
    echo ”;
    // Add the Home link
    echo ‘‘. get_bloginfo(‘name’) .’‘;

    if ( is_category() )
    {
    $catTitle = single_cat_title( “”, false );
    $cat = get_cat_ID( $catTitle );
    echo ” > “. get_category_parents( $cat, true, ” ” ) .””;
    }
    elseif ( is_archive() && !is_category() )
    {
    echo “> Archives”;
    }
    elseif ( is_search() ) {

    echo “> Search Results”;
    }
    elseif ( is_404() )
    {
    echo “> 404 Not Found<“;
    }
    elseif ( is_single() )
    {
    $category = get_the_category();
    $category_id = get_cat_ID( $category[0]->cat_name );

    echo ‘ > ‘. get_category_parents( $category_id, true, ” > ” );
    echo the_title(”,”, FALSE) .””;
    }
    elseif ( is_page() )
    {
    $post = $wp_query->get_queried_object();

    if ( $post->post_parent == 0 ){

    echo “> “.the_title(”,”, FALSE).””;

    } else {
    $title = the_title(”,”, FALSE);
    $ancestors = array_reverse( get_post_ancestors( $post->ID ) );
    array_push($ancestors, $post->ID);

    foreach ( $ancestors as $ancestor ){
    if( $ancestor != end($ancestors) ){
    echo ‘> ‘. strip_tags( apply_filters( ‘single_post_title’, get_the_title( $ancestor ) ) ) .’‘;
    } else {
    echo ‘> ‘. strip_tags( apply_filters( ‘single_post_title’, get_the_title( $ancestor ) ) ) .”;
    }
    }
    }
    }

    // End the UL
    echo “”;
    }
    }
    ?>

  • トピック「パン屑リストの親カテゴリーを非表示にしたい」には新たに返信することはできません。