{"id":961,"date":"2017-02-14T09:47:51","date_gmt":"2017-02-14T00:47:51","guid":{"rendered":"http:\/\/blue-bear.jp\/kb\/?p=961"},"modified":"2017-02-14T09:47:51","modified_gmt":"2017-02-14T00:47:51","slug":"wordpress-%e7%8f%be%e5%9c%a8%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e5%ad%90%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e3%81%bf%e3%82%92%e5%8f%96%e5%be%97","status":"publish","type":"post","link":"https:\/\/blue-bear.jp\/kb\/wordpress-%e7%8f%be%e5%9c%a8%e3%81%ae%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e5%ad%90%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%83%bc%e3%81%ae%e3%81%bf%e3%82%92%e5%8f%96%e5%be%97\/","title":{"rendered":"[wordpress] \u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u307f\u3092\u53d6\u5f97\u3059\u308b\uff08\u5b6b\u306f\u53d6\u5f97\u3057\u306a\u3044\uff09"},"content":{"rendered":"<h2>\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u307f\u3092\u53d6\u5f97\u3059\u308b\uff08\u5b6b\u306f\u53d6\u5f97\u3057\u306a\u3044\uff09<\/h2>\n<p>\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u307f\u3092\u53d6\u5f97\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5b9f\u88c5<br \/>\nget_the_category\u3067\u306a\u305c\u304b\u305d\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u304c\u5c5e\u3059\u308b\u3059\u3079\u3066\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u53d6\u5f97\u3057\u3066\u304f\u308b\u306e\u3067\u3001\u30ab\u30c6\u30b4\u30ea\u30fcID\u3092\u7279\u5b9a\u3059\u308b\u305f\u3081\u306b\u3001\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u3068\u5408\u81f4\u3059\u308bID\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081for\u3067\u30eb\u30fc\u30d7\u3057\u3066\u3044\u308b<\/p>\n<pre>\r\n<?php\r\n\t$cat = get_the_category(); \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u30ea\u30b9\u30c8\u53d6\u5f97\r\n\t$title = single_cat_title(\"\", false); \/\/\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u3092\u53d6\u5f97\u3059\u308b\r\n\tfor($i=0;$i<count($cat);$i++){\r\n\t    if($title === $cat[$i]->name){\r\n\t        $cat_id = $cat[$i]->cat_ID; \/\/\u73fe\u5728\u958b\u3044\u3066\u3044\u308b\u30ab\u30c6\u30b4\u30ea\u30fc\u3068Match\u3059\u308b\u306a\u3089\r\n\t        break;\r\n\t    }else{\r\n\t        $cat_id = 0;\r\n\t    }\r\n\t}\r\n\t?>\r\n\t<?php\r\n\t$args = array(\r\n\t    'parent' => $cat_id, \/\/\u89aa\u3092\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u3068\u3059\u308b\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u53d6\u5f97\r\n\t    'show_counts' => true, \/\/\u8a18\u4e8b\u6570\u8868\u793a\r\n\t  );\r\n\tmy_category_list($args);\r\n?>\r\n<\/pre>\n<h3>function.php<\/h3>\n<pre>\r\nfunction my_category_list($args = array()) {\r\n  \/\/\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\uff08\u5fc5\u8981\u306b\u5fdc\u3058\u3066 get_categories() \u306e\u5f15\u6570\u306b\u5bfe\u5fdc\u3059\u308b\u3082\u306e\u3092\u8ffd\u52a0\u3057\u305f\u308a\u524a\u9664\u3059\u308c\u3070\u3088\u3044\uff09\r\n  $defaults = array(\r\n    'parent' => '',  \/\/\u51fa\u529b\u3059\u308b\u89aa\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u540d\u524d\u307e\u305f\u306fID\uff080 \u3092\u6307\u5b9a\u3059\u308b\u3068\u6700\u4e0a\u4f4d\u306e\u5168\u3066\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u8aad\u307f\u8fbc\u3080\uff09\r\n    'include' => '',    \/\/\u51fa\u529b\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u3092\u30ab\u30f3\u30de\u3067\u533a\u5207\u3063\u3066\u6307\u5b9a\u3002\r\n    'exclude' => '',    \/\/\u9664\u5916\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u3092\u30ab\u30f3\u30de\u3067\u533a\u5207\u3063\u3066\u6307\u5b9a\u3002\r\n    'hide_empty' => 0,    \/\/\u8a18\u4e8b\uff08\u6295\u7a3f\uff09\u306e\u306a\u3044\u30ab\u30c6\u30b4\u30ea\u30fc\u3082\u8aad\u307f\u8fbc\u3080\u304b\u3069\u3046\u304b\uff080\uff1a\u8aad\u307f\u8fbc\u3080\u30011\uff1a\u8aad\u307f\u8fbc\u307e\u306a\u3044\uff09\r\n    'show_counts' => false,     \/\/\u8a18\u4e8b\uff08\u6295\u7a3f\uff09\u306e\u4ef6\u6570\u3092\u8868\u793a\u3059\u308b\u304b\u3069\u3046\u304b\r\n    'show_children' => false,   \/\/\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u3092\u51fa\u529b\u3059\u308b\u304b\u3069\u3046\u304b\r\n    'show_ancestor' => false,   \/\/\u5b6b\u30ab\u30c6\u30b4\u30ea\u30fc\uff08\u4ee5\u4e0b\uff09\u3092\u51fa\u529b\u3059\u308b\u304b\u3069\u3046\u304b\r\n    'orderby' => 'name',  \/\/\u4e26\u3079\u66ff\u3048\u306e\u30ad\u30fc id, slug, name, count\r\n    'order' => 'ASC',  \/\/\u4e26\u3079\u66ff\u3048\u306e\u9806\u5e8f 'ASC'\u307e\u305f\u306f'DESC'\r\n    'image_html' => '',  \/\/\u633f\u5165\u3059\u308b\u753b\u50cf\u306eHTML \u4f8b\uff1a'<img loading=\"lazy\" decoding=\"async\" src=\"'.get_template_directory_uri().'\/images\/arrow.png\" width=\"10\" height=\"10\" alt=\"\"\/>'\r\n  );\r\n  $args = wp_parse_args( $args, $defaults );    \/\/\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u89e3\u6790\u3057\u3001\u7701\u7565\u3055\u308c\u305f\u30d1\u30ec\u30e1\u30fc\u30bf\u306b\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u30bb\u30c3\u30c8\r\n  extract( $args, EXTR_SKIP );    \/\/\u30ad\u30fc\u3092\u5909\u6570\u540d\u3001\u5024\u3092\u5909\u6570\u306e\u5024\u3068\u3057\u3066\u51e6\u7406\r\n  \r\n  if(!is_numeric($parent)) {  \/\/\u89aa\u30ab\u30c6\u30b4\u30ea\u30fc\u306fID\u3067\u3082\u540d\u524d\u3067\u3082\u6307\u5b9a\u53ef\u80fd\u306a\u305f\u3081\u3001\u6570\u5024\u4ee5\u5916\u306fID\u306b\u5909\u63db\r\n    $parent = get_cat_ID(trim($parent)); \r\n  }\r\n  \r\n  $include = explode(',', $include);\r\n  $include_ids = '';    \/\/\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fcID\u306e\u30ea\u30b9\u30c8\uff08\u30ab\u30f3\u30de\u533a\u5207\u308a\u306e\u6587\u5b57\u5217\uff09\r\n  $count = count($include);\r\n  if($count) {\r\n    for($i=0; $i < $count; $i++) {    \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u304b\u3089\u30ab\u30c6\u30b4\u30ea\u30fcID\u3092\u53d6\u5f97\r\n      $include_ids .= get_cat_ID(trim($include[$i]));    \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u306e\u524d\u5f8c\u306b\u7a7a\u767d\u304c\u3042\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u53d6\u308a\u9664\u304f\r\n      if($i != $count-1) {\r\n        $include_ids .= ',';    \/\/\u6700\u5f8c\u306e\u8981\u7d20\u4ee5\u5916\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308b\r\n      }\r\n    }\r\n  }\r\n  \r\n  $exclude = explode(',', $exclude);\r\n  $exclude_ids = '';    \/\/\u9664\u5916\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fcID\u306e\u30ea\u30b9\u30c8\uff08\u30ab\u30f3\u30de\u533a\u5207\u308a\u306e\u6587\u5b57\u5217\uff09\r\n  $count = count($exclude);\r\n  if($count) {\r\n    for($i=0; $i < $count; $i++) {    \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u304b\u3089\u30ab\u30c6\u30b4\u30ea\u30fcID\u3092\u53d6\u5f97\r\n      $exclude_ids .= get_cat_ID(trim($exclude[$i]));    \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u306e\u524d\u5f8c\u306b\u7a7a\u767d\u304c\u3042\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u306e\u3067\u53d6\u308a\u9664\u304f\r\n      if($i != $count-1) {\r\n        $exclude_ids .= ',';    \/\/\u6700\u5f8c\u306e\u8981\u7d20\u4ee5\u5916\u306f\u30ab\u30f3\u30de\u3067\u533a\u5207\u308b\r\n      }\r\n    }\r\n  }\r\n  \r\n  $cats = get_categories(array(  \/\/\u4ee5\u4e0b\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u6307\u5b9a\u3057\u305f\u30ab\u30c6\u30b4\u30ea\u30fc\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5217\u3092\u5909\u6570\u306b\u4ee3\u5165\r\n    'parent' => $parent,  \/\/\u89aa\u30ab\u30c6\u30b4\u30ea\u30fc\u306eID\u306e\u6307\u5b9a\r\n    'hide_empty' => $hide_empty,  \/\/\u8a18\u4e8b\uff08\u6295\u7a3f\uff09\u306e\u306a\u3044\u30ab\u30c6\u30b4\u30ea\u30fc\u3082\u8aad\u307f\u8fbc\u3080\u304b\u3069\u3046\u304b\r\n    'include' => $include_ids,  \/\/\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fcID\u306e\u30ea\u30b9\u30c8\r\n    'exclude' => $exclude_ids,  \/\/\u9664\u5916\u3059\u308b\u30ab\u30c6\u30b4\u30ea\u30fcID\u306e\u30ea\u30b9\u30c8\r\n    'orderby' => $orderby,  \/\/\u4e26\u3079\u66ff\u3048\u306e\u30ad\u30fc\r\n    'order' => $order  \/\/\u4e26\u3079\u66ff\u3048\u306e\u9806\u5e8f\r\n  ));\r\n  \r\n  if(count($cats)) {  \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u304c\u3042\u308b\u6642\u3060\u3051\u3001\u4ee5\u964d\u306e\u51e6\u7406\u3092\u884c\u3046\r\n    echo \"<ul>\\n\";\r\n    foreach($cats as $cat) {\r\n      echo '<li>';\r\n      if($image_html != '') echo $image_html;  \/\/\u753b\u50cf\u306e\u6307\u5b9a\u304c\u3042\u308c\u3070\u633f\u5165\r\n      echo '<a href=\" ' .get_category_link($cat->term_id) . ' \">' . $cat->name . '';  \/\/\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u30ea\u30f3\u30af\u3068\u540d\u524d\u3092\u51fa\u529b\r\n      echo $show_counts  ? '<\/a> <span>(' . $cat->count . \")<\/span>\\n\" :  \"<\/a>\\n\";  \/\/$show_counts\u304c\u771f\u306e\u5834\u5408\u306f\u4ef6\u6570\u3092\u51fa\u529b\r\n      if($show_children){\r\n        \/\/\u73fe\u5728\u51e6\u7406\u4e2d\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u540d\u3001\u633f\u5165\u3059\u308b\u753b\u50cf\u3001\u5b50\u5b6b\u30ab\u30c6\u30b4\u30ea\u30fc\u51fa\u529b\u306e\u6709\u7121\u3092\u6e21\u3057\u3066\u518d\u8d77\u547c\u3073\u51fa\u3057\r\n        my_category_list(array(\r\n          'parent' => $cat->name, \r\n          'image_html' => $image_html, \r\n          'show_children' => $show_ancestor\r\n        ));  \r\n      }\r\n      echo \"<\/li>\\n\";\r\n    }\r\n    echo \"<\/ul>\\n\";\r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u5728\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u307f\u3092\u53d6\u5f97<\/p>\n","protected":false},"author":1,"featured_media":962,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[150],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/961"}],"collection":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/comments?post=961"}],"version-history":[{"count":1,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"predecessor-version":[{"id":963,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/posts\/961\/revisions\/963"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media\/962"}],"wp:attachment":[{"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blue-bear.jp\/kb\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}