{"id":10986,"date":"2026-02-13T17:24:30","date_gmt":"2026-02-13T08:24:30","guid":{"rendered":"https:\/\/code-plus.jp\/gp\/?p=10986"},"modified":"2026-02-13T17:31:04","modified_gmt":"2026-02-13T08:31:04","slug":"wordpress-10986","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/wordpress-10986\/","title":{"rendered":"\u3010WordPress\u3011[part=\"parts\/file.php\"]\u3067\u3001php\u30d5\u30a1\u30a4\u30eb\u3092\u547c\u3073\u51fa\u3059\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9"},"content":{"rendered":"<pre><code class=\"language-php\">&lt;?php \/\/\uff08shortcodes.php\uff09\r\n\r\n\/* PHP\u30d5\u30a1\u30a4\u30eb include \u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\r\n* <div id=\"&quot;ID\u540d&quot;\" class=\"&quot;\u30af\u30e9\u30b9\u540d&quot;\"><\/div>\u3067\u3001php\u30d5\u30a1\u30a4\u30eb\u3092\u547c\u3073\u51fa\u3057\r\n====================================== *\/\r\nfunction shortcode_part_file($params = array()) {\r\n  $params = shortcode_atts(array(\r\n    &#39;file&#39; =&gt; &#39;&#39;,\r\n    &#39;id&#39;   =&gt; &#39;&#39;,\r\n    &#39;class&#39; =&gt; &#39;&#39;\r\n  ), $params, &#39;part&#39;);\r\n\r\n  $file = $params[&#39;file&#39;];\r\n\r\n  \/\/ <div><\/div> \u5f62\u5f0f\u3078\u306e\u5bfe\u5fdc\r\n  \/\/ WordPress\u306f <div><\/div> \u3092 $params[0] =&gt; &#39;=&quot;value&quot;&#39; \u3068\u3057\u3066\u6e21\u3059\r\n  if (empty($file) &amp;&amp; !empty($params[0])) {\r\n    $file = trim($params[0], &#39;=&quot;\\&#39;&#39;);\r\n  }\r\n\r\n  if (empty($file)) return &#39;&#39;;\r\n\r\n  ob_start();\r\n\r\n  echo &#39;&lt;div&#39; .\r\n    (!empty($params[&#39;id&#39;])    ? &#39; id=&quot;&#39; . esc_attr($params[&#39;id&#39;]) . &#39;&quot;&#39; : &#39;&#39;) .\r\n    (!empty($params[&#39;class&#39;]) ? &#39; class=&quot;&#39; . esc_attr($params[&#39;class&#39;]) . &#39;&quot;&#39; : &#39;&#39;) .\r\n    &#39;&gt;&#39;;\r\n\r\n  \/\/ .php \u304c\u542b\u307e\u308c\u3066\u3044\u306a\u3051\u308c\u3070\u4ed8\u4e0e\uff08\u3069\u3061\u3089\u306e\u66f8\u304d\u65b9\u3067\u3082\u52d5\u304f\u3088\u3046\u306b\uff09\r\n  $filename = pathinfo($file, PATHINFO_EXTENSION) === &#39;php&#39; ? $file : $file . &#39;.php&#39;;\r\n\r\n  \/\/ \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30c8\u30e9\u30d0\u30fc\u30b5\u30eb\u5bfe\u7b56\r\n  $filename = str_replace(&#39;..&#39;, &#39;&#39;, $filename);\r\n\r\n  $file_path = get_stylesheet_directory() . &#39;\/&#39; . $filename;\r\n\r\n  if (file_exists($file_path)) {\r\n    include($file_path);\r\n  } else {\r\n    if (defined(&#39;WP_DEBUG&#39;) &amp;&amp; WP_DEBUG) {\r\n      echo &#39;&lt;!--  \u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093: &#39; . esc_html($filename) . &#39; --&gt;&#39;;\r\n    }\r\n  }\r\n\r\n  echo &#39;&lt;\/div&gt;&#39;;\r\n\r\n  return ob_get_clean();\r\n}\r\nadd_shortcode(&#39;part&#39;, &#39;shortcode_part_file&#39;);\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"&lt;?php \/\/\uff08shortcodes.php\uff09 \/* PHP\u30d5\u30a1\u30a4\u30eb include \u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9 * \u3067\u3001php\u30d5\u30a1\u30a4\u30eb\u3092\u547c\u3073\u51fa\u3057 ======================================[...]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","footnotes":"","vk-ltc-link":"","vk-ltc-target":"0"},"categories":[13],"tags":[],"class_list":["post-10986","post","type-post","status-publish","format-standard","category-wordpress"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/10986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/comments?post=10986"}],"version-history":[{"count":0,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/10986\/revisions"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=10986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=10986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=10986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}