{"id":982,"date":"2024-04-02T12:31:20","date_gmt":"2024-04-02T03:31:20","guid":{"rendered":"https:\/\/yuzum.com\/blog\/?p=982"},"modified":"2024-05-14T08:44:26","modified_gmt":"2024-05-13T23:44:26","slug":"wordpress-if","status":"publish","type":"post","link":"https:\/\/yuzum.com\/blog\/20240402_wordpress-if","title":{"rendered":"wordpress \u6761\u4ef6\u5206\u5c90\u3010\u7279\u5b9a\u306e\u89aa\u30ab\u30c6\u30b4\u30ea\u306b\u5c5e\u3059\u308b\u5834\u5408\u3011"},"content":{"rendered":"<p>\u7279\u5b9a\u306e\u89aa\u30ab\u30c6\u30b4\u30ea\u306b\u5c5e\u3059\u308b\u5b50\u30ab\u30c6\u30b4\u30ea\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u5834\u5408\uff08\u305f\u304f\u3055\u3093\u306a\u304f\u3066\u3082\u3044\u3044\u3051\u3069\uff09\u3001\u6761\u4ef6\u5206\u5c90\u3067\u5b50\u30ab\u30c6\u30b4\u30ea\u3092\u6307\u5b9a\u3059\u308b\u3068\u6570\u591a\u304f\u306e\u6307\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u975e\u5e38\u306b\u624b\u9593\u304c\u304b\u304b\u308b\u3002<br>\u305d\u306e\u4e0a\u3001\u5b50\u30ab\u30c6\u30b4\u30ea\u304c\u5897\u3048\u305f\u5834\u5408\u306b\u307e\u305f\u305d\u306e\u6307\u5b9a\u3082\u66f8\u304d\u63db\u3048\u304c\u5fc5\u8981\u306a\u306e\u3067\u3001\u89aa\u30ab\u30c6\u30b4\u30ea\u3092\u6307\u5b9a\u3059\u308b\u65b9\u6cd5\u304c\u4fbf\u5229\u3067\u3059\u3002<\/p>\r\n\r\n<p>\u3053\u308c\u3001\u672c\u5f53\u306b\u4f7f\u3044\u3084\u3059\u3044\u3067\u3059\uff01<\/p>\r\n<h2>functions.php\u306b\u8a18\u8ff0<\/h2>\r\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nif ( ! function_exists( 'post_is_in_descendant_category' ) ) {\r\n    function post_is_in_descendant_category( $cats, $_post = null ) {\r\n        foreach ( (array) $cats as $cat ) {\r\n            $descendants = get_term_children( (int) $cat, 'category' );\r\n            if ( $descendants &amp;&amp; in_category( $descendants, $_post ) )\r\n                return true;\r\n        }\r\n        return false;\r\n    }\r\n}\r\n<\/pre>\r\n\r\n<h2>\u6761\u4ef6\u5206\u5c90\u3057\u305f\u3044\u5834\u6240\u306b\u8a18\u8ff0<\/h2>\r\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php if ( in_category(\u89aa\u30ab\u30c6\u30b4\u30eaID) || post_is_in_descendant_category(\u89aa\u30ab\u30c6\u30b4\u30eaID) ): ?&gt;\r\n\u3000\u3000\u3000\u3000\/\/ \u300c\u89aa\u30ab\u30c6\u30b4\u30ea\u300d\u3082\u3057\u304f\u306f\u300c\u89aa\u30ab\u30c6\u30b4\u30ea\u300d\u306b\u5c5e\u3059\u308b\u5b50\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u3082\u306e\u3067\u3042\u3063\u305f\u5834\u5408\u306e\u51fa\u529b\u5185\u5bb9\r\n&lt;?php else: ?&gt;\r\n\u3000\u3000\u3000\u3000\/\/ \u3000\u305d\u308c\u4ee5\u5916\u306e\u51fa\u529b\u5185\u5bb9\r\n&lt;?php endif; ?&gt;\r\n<\/pre>\r\n<p>\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u53c2\u7167\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3057\u305f<br>\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\uff01<br><a href=\"https:\/\/apr20.net\/web\/wordpress-web-category\/3373\/\" rel=\"noopener\" target=\"_blank\">WordPress\u3067\u7279\u5b9a\u306e\u89aa\u30ab\u30c6\u30b4\u30ea\u3068\u305d\u306e\u5b50\u30ab\u30c6\u30b4\u30ea\u306b\u6240\u5c5e\u3059\u308b\u5834\u5408\u306e\u6761\u4ef6\u5206\u5c90\u306e\u65b9\u6cd5<\/a><\/p>\r\n\r\n","protected":false},"excerpt":{"rendered":"\u7279\u5b9a\u306e\u89aa\u30ab\u30c6\u30b4\u30ea\u306b\u5c5e\u3059\u308b\u5b50\u30ab\u30c6\u30b4\u30ea\u304c\u305f\u304f\u3055\u3093\u3042\u308b\u5834\u5408\uff08\u305f\u304f\u3055\u3093\u306a\u304f\u3066\u3082\u3044\u3044\u3051\u3069\uff09\u3001\u6761\u4ef6\u5206\u5c90\u3067\u5b50\u30ab\u30c6\u30b4\u30ea\u3092\u6307\u5b9a\u3059\u308b\u3068\u6570\u591a\u304f\u306e\u6307\u5b9a\u304c\u5fc5\u8981\u306b\u306a\u308b\u306e\u3067\u975e\u5e38\u306b\u624b\u9593\u304c\u304b\u304b\u308b\u3002\u305d\u306e\u4e0a\u3001\u5b50\u30ab\u30c6\u30b4\u30ea\u304c\u5897\u3048\u305f\u5834\u5408\u306b\u307e\u305f\u305d ... ","protected":false},"author":1,"featured_media":1021,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-982","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"_links":{"self":[{"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/posts\/982","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/comments?post=982"}],"version-history":[{"count":5,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/posts\/982\/revisions"}],"predecessor-version":[{"id":987,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/posts\/982\/revisions\/987"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/media\/1021"}],"wp:attachment":[{"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/media?parent=982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/categories?post=982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yuzum.com\/blog\/wp-json\/wp\/v2\/tags?post=982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}