作成日: 2022/08/11 更新日: 2023/03/25 サイトの紹介と使い方
初めに
- function Codeの分類、構成は、筆者が独自に行っています。
- ファイル(置き場所):テーマCocoon childのfunctions.php
- 分類コード:22xx
内容
説明
- 機能:パン屑リストをHTML文字列として返します。
- 引数:無し
- 戻り値:HTML文字列
- 下記のHTMLが戻り値の例です。
- カテゴリの階層によって、表示される項目が増減します。
例1
<ul id="my_top" class="my-bread-crumb">
<li><a href="https://aidendo-pilot.com/">top</a></li>
<li><a href="https://aidendo-pilot.com/">WEB</a></li>
</ul>
<span class="my-bread-crumb_title">< WordPress ></span>

- 赤枠がパン屑リストです。
- 青枠が記事のタイトルです。
例2
<ul id="my_top" class="my-bread-crumb">
<li><a href="https://aidendo-pilot.com/">top</a></li>
<li><a href="https://aidendo-pilot.com/">WEB</a></li>
<li><a href="https://aidendo-pilot.com/cat_parent_WordPress">WordPress</a></li>
</ul>
<span class="my-bread-crumb_title">< functionCode_WordPress ></span>

- 赤枠がパン屑リストです。
- 青枠が記事のタイトルです。
例3
<ul id="my_top" class="my-bread-crumb">
<li><a href="https://aidendo-pilot.com/">top</a></li>
<li><a href="https://aidendo-pilot.com/">WEB</a></li>
<li><a href="https://aidendo-pilot.com/cat_parent_WordPress">WordPress</a></li>
<li><a href="https://aidendo-pilot.com/cat_child_functionCode_wordpress">functionCode</a></li>
</ul>
<span class="my-bread-crumb_title">< 11.サイト独自の情報をGETする関数 ></span>

- 赤枠がパン屑リストです。
- 青枠が記事のタイトルです。
ソースコード
//<--- 2204
function my_bread_crumb_parts($atts){
$post = get_post();
$ret .= "<ul id=\"my_top\" class=\"my-bread-crumb\">";
$ret .= my_set_list_a_tag( "/","top" );
if( has_tag("20nonecategory",$post) ):
elseif( has_tag("81parent_cat",$post) ):
$catr = $post->post_title;
$arg2 = my_get_menu_title( $catr );
$ret .= my_set_list_a_tag( "/",$arg2 );
elseif( has_tag("82child_cat",$post) ):
$categorys = get_the_category();
$parent = get_the_category_by_ID( $categorys[0]->category_parent );
$catr = $parent;
$arg2 = my_get_menu_title( $catr );
$ret .= my_set_list_a_tag( "/",$arg2 );
$arg1 = "/cat_parent_" . $parent;
$ret .= my_set_list_a_tag( $arg1,$parent );
elseif( has_tag("21parent",$post) ):
$categorys = get_the_category();
$parent = get_the_category_by_ID( $categorys[0]->term_id );
$catr = $parent;
$arg2 = my_get_menu_title( $catr );
$ret .= my_set_list_a_tag( "/",$arg2 );
$arg1 = "/cat_parent_" . $parent;
$ret .= my_set_list_a_tag( $arg1,$parent );
elseif( has_tag("22child",$post) ):
$categorys = get_the_category();
$parent = get_the_category_by_ID( $categorys[0]->category_parent );
$catr = $parent;
$arg2 = my_get_menu_title( $catr );
$ret .= my_set_list_a_tag( "/",$arg2 );
$arg1 = "/cat_parent_" . $parent;
$ret .= my_set_list_a_tag( $arg1,$parent );
$child = get_the_category_by_ID( $categorys[0]->term_id );
$arg1 = "/cat_child_" . $child;
if( stristr($child,"samplecode") ):
$child = "sampleCode";
elseif( stristr($child,"functioncode") ):
$child = "functionCode";
elseif( stristr($child,"class") ):
$child = "class";
endif;
$ret .= my_set_list_a_tag( $arg1,$child );
endif;
$ret .= "</ul>";
$ret .= "<span class=\"my-bread-crumb_title\">" . "< " . $post->post_title . " >" . "</span>";
my_debug_shortcode_echo( "my_bread_crumb_parts.txt",$ret );
return $ret;
}
// 2204 --->
CSS
- 01.パン屑リストのCSSを参照してください。