created: 2021/07/31 modified: 2021/09/14
初めに
ファイル:Cocoon childのfunctions.php
関数の分類コード:01xx
次の記事のマイルールに従ってショートコードを作っています。
WordPressでマイルールを決めて記事の管理をする
ソースコード
ぱんくずリスト
全ての投稿ページで共有のぱんくずリストです。
mysc_mail からページ内ジャンプできるように<ul>タグにid:my_top を付けています。
//<--- 0101
add_shortcode('mysc_bread_crumb', 'my_bread_crumb');
function my_bread_crumb($atts){
$post = get_post();
$ret = "<ul id=\"my_top\" class=\"my-bread-crumb\">";
$ret .= my_set_list_a_tag( "/","menu" );
if( has_tag("81parent_cat",$post) ):
elseif( has_tag("82child_cat",$post) ):
$categorys = get_the_category();
$parent = get_the_category_by_ID( $categorys[0]->category_parent );
$arg1 = "/category_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 );
$arg1 = "/category_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 );
$arg1 = "/category_parent_" . $parent;
$ret .= my_set_list_a_tag( $arg1,$parent );
$child = get_the_category_by_ID( $categorys[0]->term_id );
$arg1 = "/category_child_" . $child;
if( strstr($child,"sample") ):
$child = "sample";
elseif( strstr($child,"function") ):
$child = "function";
endif;
$ret .= my_set_list_a_tag( $arg1,$child );
endif;
$ret .= "<li> /</li>";
$ret .= "</ul>";
return $ret;
}
// 0101 --->
子カテゴリのMenu リスト
親カテゴリページで使う子カテゴリのMenu リストです。
//<--- 0102
add_shortcode('mysc_show_child_category_on_parent', 'mysc_show_child_category_on_parent');
function mysc_show_child_category_on_parent($atts){
$ret = "<ul class=\"my-menu-list\">";
$categorys = get_the_category();
$args = array(
'type' => 'post',
'child_of' => $categorys[0]->term_id
);
$categories = get_categories( $args );
foreach ($categories as $category):
$arg1 = "/category_child_" . $category->cat_name;
if( strstr($category->cat_name,"sample") ):
$arg2 = "sample";
elseif( strstr($category->cat_name,"function") ):
$arg2 = "function";
else:
$arg2 = $category->cat_name;
endif;
$ret .= my_set_list_a_tag( $arg1,$arg2 );
endforeach;
$ret .= "</ul>";
return $ret;
}
// 0102 --->
<!-- wp:shortcode -->
[mysc_article_list modified DESC]
<!-- /wp:shortcode -->
メールアドレス: