41.子カテゴリの一覧を表示

作成日: 2022/08/24 更新日: 2023/03/25 サイトの紹介と使い方

初めに

  1. 筆者が独自にfunctionを分類、構成しています。
  2. ファイル(置き場所):テーマCocoon childのfunctions.php
  3. 分類コード:22xx

内容

説明

  1. 機能:子カテゴリの一覧を親カテゴリページに表示します。
  2. 引数:無し
  3. 戻り値:HTML戻り値
    1. 下記のHTMLは戻り値の例です。
<!-- wp:paragraph --><br>
  <ul class="my-menu-list">
    <li><a href="https://aidendo-pilot.com/cat_child_cocoon">cocoon</a></li>
    <li><a href="https://aidendo-pilot.com/cat_child_functionCode_wordpress">functionCode</a></li>
    <li><a href="https://aidendo-pilot.com/cat_child_ShortCode">ShortCode</a></li>
  </ul>
<br><!-- /wp:paragraph -->

ソースコード

//<--- 2211
function my_show_child_category_parts($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      = "/cat_child_" . $category->cat_name;
    if( stristr($category->cat_name,"samplecode") ):
      $arg2 = "sampleCode";
    elseif( stristr($category->cat_name,"functioncode") ):
	   $arg2 = "functionCode";
    elseif( stristr($category->cat_name,"class") ):
	   $arg2 = "class";
    else:
      $arg2 = $category->cat_name;
    endif;
    $ret      .= my_set_list_a_tag( $arg1,$arg2 );
  endforeach;

  $ret .= "</ul>";
	
//  my_debug_shortcode_echo( "my_show_child_category_parts.txt",$ret );

  return $ret;
}
// 2211 --->

CSS

/*<--- 0203 */
.my-menu-list li{
  position:         relative;
  display:          inline;
  list-style:        square-button;
  border-style:		solid;
  border-radius:	1rem;
  font-size:        1.5rem;
  font-weight:     bold;
  padding:			  0.3rem;
}

.my-menu-list li a {
  text-decoration: none;
}

.my-menu-list li a:hover {
  text-decoration: underline;
}
/* 0203 --->*/

  1. 赤枠の中が子カテゴリのリストです。

お問合せ・御要望

お問合せ
Verified by MonsterInsights
タイトルとURLをコピーしました