パンくずでカスタム投稿のリンクが出力されない
-
WordPressでパンくずを作成していますが、カスタム投稿のリンク先が出力されません。
通常の投稿タイプ(/info/)とカスタム投稿で作ったスタッフ紹介(/staff/)がありますが、カスタム投稿(/staff/)だけ、文字は表示されますが、リンクがこんな感じで空になってしまいます。
下記のようにの中にスタッフ紹介の戻り先のリンクを設定したいだけなのですが、どのようにすれば良いでしょうか?function breadcrumb(){ global $post; $itemtype = ' itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem"'; $arrow = '>'; /* 新着情報(投稿タイプ) */ $post_top = '<li'.$itemtype.'> <a href="'.esc_url(home_url('/')).'info/"><span>新着情報</span></a>'.$arrow.'<meta itemprop="position" content="2" /></li> '; $str = ''; if(!is_home() && !is_admin()): $str .= '<ol itemscope itemtype="https://schema.org/BreadcrumbList"> <li itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">'; $str .= ' <a href="'.esc_url(home_url()).'" itemprop="item"><span itemprop="name">ホーム</span></a>'.$arrow.'<meta itemprop="position" content="1" /></li>'; if(is_category()): $str .= $post_top; $cat = get_queried_object(); if($cat->parent != 0): $ancestors = array_reverse(get_ancestors($cat->cat_ID, 'category')); foreach($ancestors as $ancestor): $str .= '<li'.$itemtype.'><a href="'.esc_url(get_category_link($ancestor)).'" itemprop="item"><span itemprop="name">'.esc_html(get_cat_name($ancestor)).'</span></a>'.$arrow.'</li>'; endforeach; endif; $str .= '<li>'.esc_html($cat->cat_name).'</li>';/* カテゴリーのタイトル */ elseif(is_page()): if($post->post_parent != 0): $ancestors = array_reverse(get_post_ancestors($post->ID)); foreach($ancestors as $ancestor): $str .= '<li'.$itemtype.'><a href="'.esc_url(get_permalink($ancestor)).'" itemprop="item"> <span class="title">'.esc_html(get_the_title($ancestor)).'</span></a>'.$arrow.'</li>'; endforeach; endif; $str .= '<li>'.esc_html(get_the_title()).'</li>'; elseif(is_single()): if(is_singular('post')) $str .= $post_top; $categories = get_the_category($post->ID); if($categories): if($categories[0]->parent != 0): $parent_cat = get_the_category_by_ID($categories[0]->parent); $str .= '<li'.$itemtype.'> <a href="'.esc_url(get_category_link($categories[0]->parent)).'" itemprop="item"><span itemprop="name">'.esc_html($parent_cat).'</span></a>'.$arrow.'</li>'; else: $str .= '<li'.$itemtype.'><a href="'.esc_url(get_category_link($categories[0]->cat_ID)).'" itemprop="item"> <span itemprop="name">'.esc_html($categories[0]->name).'</span></a>'.$arrow.'<meta itemprop="position" content="3" /></li>'; endif; endif; $post_type = get_query_var('post_type'); if($post_type): $str .= '<li'.$itemtype.'><a href="'.esc_url(get_post_type_archive_link($post_type)).'" itemprop="item"><span itemprop="name">'.esc_html(get_post_type_object($post_type)->label).'</span> </a>'.$arrow.'<meta itemprop="position" content="2" /></li>'; endif; $str .= '<li>'.esc_html(get_the_title()).'</li>';/* 記事のタイトル*/ endif; $str .= '</ol>'; endif; echo $str; }
2件の返信を表示中 - 1 - 2件目 (全2件中)
2件の返信を表示中 - 1 - 2件目 (全2件中)
- トピック「パンくずでカスタム投稿のリンクが出力されない」には新たに返信することはできません。