{"id":11,"date":"2016-01-15T18:01:16","date_gmt":"2016-01-15T09:01:16","guid":{"rendered":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/?p=11"},"modified":"2016-02-01T19:05:11","modified_gmt":"2016-02-01T10:05:11","slug":"wordpress%e3%81%a7%e7%89%b9%e5%ae%9a%e3%82%a8%e3%83%b3%e3%83%88%e3%83%aa%e3%81%ae%e6%89%80%e5%b1%9e%e3%82%ab%e3%83%86%e3%82%b4%e3%83%aa%e3%82%92%e3%80%8c%e8%a6%aa%e2%86%92%e5%ad%90%e3%80%8d%e3%81%ae","status":"publish","type":"post","link":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/11","title":{"rendered":"WordPress\u3067\u7279\u5b9a\u30a8\u30f3\u30c8\u30ea\u306e\u6240\u5c5e\u30ab\u30c6\u30b4\u30ea\u3092\u300c\u89aa\u2192\u5b50\u300d\u306e\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b"},"content":{"rendered":"<p>\u4f8b\u3048\u3070\u3053\u3046\u3044\u3046\u3001\u89aa\u5b50\u95a2\u4fc2\u306e\u3042\u308b\u30ab\u30c6\u30b4\u30ea\u69cb\u6210\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059<\/p>\n<p>\u52c7\u8005<br \/>\n\u3000\u30fc\u6642\u306e\u52c7\u8005<br \/>\n\u3000\u30fc\u98a8\u306e\u52c7\u8005<br \/>\n\u3000\u30fc\u795e\u306b\u9078\u3070\u308c\u3057\u52c7\u8005<\/p>\n<p>\u3042\u308b\u8a18\u4e8b\u3092\u300c\u52c7\u8005\u3000\u98a8\u306e\u52c7\u8005\u300d\u306e\u30ab\u30c6\u30b4\u30ea\u306b\u6307\u5b9a\u3057\u305f\u5834\u5408\u3001\u666e\u901a\u306bget_the_category()\u3092\u4f7f\u3046\u3068\u300c\u52c7\u8005\u3000\u98a8\u306e\u52c7\u8005\u300d\u3067\u306f\u306a\u304f\u6a5f\u68b0\u7684\u306b\u30a2\u30eb\u30d5\u30a1\u30d9\u30c3\u30c8\u9806\u306b\u300c\u98a8\u306e\u52c7\u8005\u3000\u52c7\u8005\u300d\u3068\u4e26\u3079\u3089\u308c\u3066\u3057\u307e\u3063\u3066\u30f4\u30a1\u30fc\u3068\u306a\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059<\/p>\n<p>\u8a66\u884c\u932f\u8aa4\u30672\u30d1\u30bf\u30fc\u30f3\u307b\u3069\u5bfe\u51e6\u6cd5\u3092\u8a66\u3057\u305f\u306e\u3067\u4e21\u65b9\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059<\/p>\n<h4>\u89e3\u6cd5\u305d\u306e1<\/h4>\n<p>\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u8a18\u4e8b\u3067\u3059\u3002\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<br \/>\n<a href=\"http:\/\/tipsbear.com\/wordpress-taxonomy-get-terms-listing-in-order-of-parent-child\/\" target=\"_blank\">\u30ab\u30b9\u30bf\u30e0\u30bf\u30af\u30bd\u30ce\u30df\u30fc\u306b\u89aa\u5b50\u95a2\u4fc2\uff08\u968e\u5c64\uff09\u3092\u6301\u305f\u305b\u3001\u8907\u6570\u9078\u629e\u3057\u305f\u30bf\u30fc\u30e0\u306e\u4e26\u3073\u9806\u3092\u89aa\uff1e\u5b50\u306e\u9806\u756a\u306b\u8868\u793a\u3059\u308b<\/a><br \/>\n\u203b\u300cchildren[]\u300d\u3068\u3044\u3046\u7b87\u6240\u304c\u81ea\u5206\u306e\u74b0\u5883\u3067\u306f\u52d5\u4f5c\u3057\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u81ea\u5206\u306a\u308a\u306b\u66f8\u304d\u63db\u3048\u307e\u3057\u305f\u304c\u3001\u3061\u3087\u3063\u3068\u982d\u306e\u60aa\u3044\u51e6\u7406\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002\u3054\u3081\u3093\u3002<\/p>\n<p>functions.php<\/p>\n<pre>\r\n\/\/\u5f15\u6570\u3068\u3057\u3066\u4e0e\u3048\u305f\u914d\u5217\u3092\u89aa\u5b50\u9806\u306b\r\nfunction getRootTaxonomies($terms=null){\r\n\t$rootterms = array();\r\n\t$roottermstemp = array();\r\n\tif(isset($terms))\r\n\t{\r\n\t\tforeach($terms as $k=>$v){\r\n\t\t\tif($v->parent === 0){\r\n\t\t\t\t$rootterms[] = $v;\r\n\t\t\t}\r\n\t\t}\r\n\t\tforeach($rootterms as $k=>$v)\r\n\t\t{\r\n\t\t\t$i = 0;\r\n\t\t\tforeach($terms as $sk=>$sv){\r\n\t\t\t\t$childname = 'child'.$i;\r\n\t\t\t\tif( $v->term_id === $sv->parent){\r\n\t\t\t\t\t$rootterms[$k]->$childname  = $sv;\r\n\t\t\t\t\t$i++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn $rootterms;\r\n}\r\n<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u8a72\u5f53\u7b87\u6240<\/p>\n<pre>\r\n<?php \r\n$categorytree = getRootTaxonomies( get_the_category() );\r\nforeach($categorytree as $pv){\r\n\/\/\u30b9\u30e9\u30c3\u30b0\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?= $pv->slug; ?>\r\n\/\/\u30ab\u30c6\u30b4\u30ea\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?=$pv->name; ?>\r\n<?php\r\n\tfor ($i = 0; $i<=4; $i++){ \/\/4\u3068\u3044\u3046\u6570\u5b57\u306f\u9069\u5f53\u3002\u30ab\u30c6\u30b4\u30ea\u6570\u304c\u591a\u3044\u3068\u304d\u306f\u3082\u3046\u5c11\u3057\u5927\u304d\u3081\u306b\r\n\t\t$childname = 'child'.$i;\r\n\t\t\tif($pv->$childname && $pv->$childname->name != ''){\r\n?>\r\n\/\/\u30b9\u30e9\u30c3\u30b0\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?= $pv->$childname->slug; ?>\r\n\/\/\u30ab\u30c6\u30b4\u30ea\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?=$pv->$childname->name; ?>\r\n<?php \r\n\t\t}\r\n\t}\r\n}\r\n?>\r\n<\/pre>\n<h4>\u89e3\u6cd5\u305d\u306e2<\/h4>\n<p>\u3053\u3063\u3061\u306e\u65b9\u6cd5\u3067\u306f\u3001\u968e\u5c64\u306e\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u3092\u8907\u6570\u6307\u5b9a\u3057\u305f\u5834\u5408\u306f\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u3067\u3059\u3002<\/p>\n<p>\u53c2\u8003\u306b\u3055\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u306e\u306f\u4e0b\u8a18\u306e\u4e8c\u3064\u306e\u8a18\u4e8b\u3067\u3059\u3002\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<br \/>\n<a href=\"http:\/\/wordpress.hitsuji.me\/categories-id-array\/\" target=\"_blank\">\u30ab\u30c6\u30b4\u30eaID\u3092\u968e\u5c64\u9806\u306b\u4e26\u3079\u305f\u914d\u5217\u3092\u3064\u304f\u308b\u3000Wordpress\u30c6\u30fc\u30de\u306e\u4f5c\u308a\u65b9<\/a><br \/>\n<a href=\"http:\/\/hack.aipo.com\/archives\/1080\/\" target=\"_blank\">\u30ab\u30c6\u30b4\u30eaID\u304b\u3089\u30ab\u30c6\u30b4\u30ea\u540d\/\u30b9\u30e9\u30c3\u30b0\u3092\u53d6\u5f97\u3059\u308b<\/a><\/p>\n<p>function.php<\/p>\n<pre>\r\n\/\/\u6240\u5c5e\u30ab\u30c6\u30b4\u30ea\u4e00\u89a7\u3092\u89aa\u5b50\u9806\u306b\r\nfunction get_categories_tree() {\r\n    $post_categories = get_the_category();\r\n    $cat_trees = array();\r\n    $cat_counts = array();\r\n    $cat_depth_max = 10;\r\n    foreach ( $post_categories as $post_category ) {\r\n        $depth = 0;\r\n        $cat_IDs = array($post_category->cat_ID);\r\n        $cat_obj = $post_category;\r\n        while ( $depth < $cat_depth_max ) {\r\n            if ( $cat_obj->category_parent == 0 ) {\r\n                break;\r\n            }\r\n            $cat_obj = get_category($cat_obj->category_parent);\r\n            array_unshift($cat_IDs, $cat_obj->cat_ID);\r\n            $depth++;\r\n        }\r\n        array_push($cat_trees, $cat_IDs);\r\n        array_push($cat_counts, count($cat_IDs));\r\n    }\r\n    $depth_max = max($cat_counts);\r\n    $cat_key = array_search($depth_max, $cat_counts);\r\n    $cat_tree = $cat_trees[$cat_key];\r\n    return $cat_tree;\r\n}\r\n\/\/\u30ab\u30c6\u30b4\u30eaID\u304b\u3089\u30ab\u30c6\u30b4\u30ea\u540d\u3068\u30b9\u30e9\u30c3\u30b0\u53d6\u5f97\r\n    function get_category_name_by_id($cat_ID,$type) {\r\n        $cat_ID = (int) $cat_ID;\r\n        $category = get_category($cat_ID);\r\n        if($type == 'name'){\r\n            return $category->cat_name;\r\n        } elseif($type == 'slug') {\r\n            return $category->slug;\r\n        }\r\n    }\r\n<\/pre>\n<p>\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306e\u8a72\u5f53\u7b87\u6240<\/p>\n<pre>\r\n<?php \r\n$categorytree = get_categories_tree();\r\nfor ($i=0; $i<count($categorytree); $i++){\r\n?>\r\n\/\/\u30b9\u30e9\u30c3\u30b0\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?= get_category_name_by_id($categorytree[$i], slug); ?>\r\n\/\/\u30ab\u30c6\u30b4\u30ea\u3092\u51fa\u529b\u3057\u305f\u3044\u5834\u5408\r\n<?= get_category_name_by_id($categorytree[$i], name); ?>\r\n<?php \r\n}\r\n?>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b\u3048\u3070\u3053\u3046\u3044\u3046\u3001\u89aa\u5b50\u95a2\u4fc2\u306e\u3042\u308b\u30ab\u30c6\u30b4\u30ea\u69cb\u6210\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059 \u52c7\u8005 \u3000\u30fc\u6642\u306e\u52c7\u8005 \u3000\u30fc\u98a8\u306e\u52c7\u8005 \u3000\u30fc\u795e\u306b\u9078\u3070\u308c\u3057\u52c7\u8005 \u3042\u308b\u8a18\u4e8b\u3092\u300c\u52c7\u8005\u3000\u98a8\u306e\u52c7\u8005\u300d\u306e\u30ab\u30c6\u30b4\u30ea\u306b\u6307\u5b9a\u3057\u305f\u5834\u5408\u3001\u666e\u901a\u306bget_the_category()\u3092\u4f7f\u3046\u3068 &hellip; <a href=\"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/11\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;WordPress\u3067\u7279\u5b9a\u30a8\u30f3\u30c8\u30ea\u306e\u6240\u5c5e\u30ab\u30c6\u30b4\u30ea\u3092\u300c\u89aa\u2192\u5b50\u300d\u306e\u9806\u306b\u4e26\u3073\u66ff\u3048\u308b&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/posts\/11"}],"collection":[{"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":16,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":96,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/posts\/11\/revisions\/96"}],"wp:attachment":[{"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shinnoji.main.jp\/jimen75th\/blog\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}