{"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-10-28T20:14:31","modified_gmt":"2026-10-28T11:14:31","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\n\n\/* PHP\u30d5\u30a1\u30a4\u30eb include \u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\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\n\u0fd0\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u2740\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u0f04 *\/\nfunction shortcode_part_file($params = array()) {\n  $params = shortcode_atts(array(\n    &#39;file&#39; =&gt; &#39;&#39;,\n    &#39;id&#39;   =&gt; &#39;&#39;,\n    &#39;class&#39; =&gt; &#39;&#39;\n  ), $params, &#39;part&#39;);\n\n  $file = $params[&#39;file&#39;];\n\n  \/\/ <div><\/div> \u5f62\u5f0f\u3078\u306e\u5bfe\u5fdc\n  \/\/ WordPress\u306f <div><\/div> \u3092 $params[0] =&gt; &#39;=&quot;value&quot;&#39; \u3068\u3057\u3066\u6e21\u3059\n  if (empty($file) &amp;&amp; !empty($params[0])) {\n    $file = trim($params[0], &#39;=&quot;\\&#39;&#39;);\n  }\n\n  if (empty($file)) return &#39;&#39;;\n\n  ob_start();\n\n  echo &#39;&lt;div&#39; .\n    (!empty($params[&#39;id&#39;])    ? &#39; id=&quot;&#39; . esc_attr($params[&#39;id&#39;]) . &#39;&quot;&#39; : &#39;&#39;) .\n    (!empty($params[&#39;class&#39;]) ? &#39; class=&quot;&#39; . esc_attr($params[&#39;class&#39;]) . &#39;&quot;&#39; : &#39;&#39;) .\n    &#39;&gt;&#39;;\n\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\n  $filename = pathinfo($file, PATHINFO_EXTENSION) === &#39;php&#39; ? $file : $file . &#39;.php&#39;;\n\n  \/\/ \u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u30c8\u30e9\u30d0\u30fc\u30b5\u30eb\u5bfe\u7b56\n  $filename = str_replace(&#39;..&#39;, &#39;&#39;, $filename);\n\n  $file_path = get_stylesheet_directory() . &#39;\/&#39; . $filename;\n\n  if (file_exists($file_path)) {\n    include($file_path);\n  } else {\n    if (defined(&#39;WP_DEBUG&#39;) &amp;&amp; WP_DEBUG) {\n      echo &#39;&lt;!--  \u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093: &#39; . esc_html($filename) . &#39; --&gt;&#39;;\n    }\n  }\n\n  echo &#39;&lt;\/div&gt;&#39;;\n\n  return ob_get_clean();\n}\nadd_shortcode(&#39;part&#39;, &#39;shortcode_part_file&#39;);\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 \u0fd0\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u2740\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u22b0\u27e1\u22b1\u0f36\u0f04 *\/ funct[...]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"group":[],"pg":[],"class_list":["post-10986","post","type-post","status-publish","format-standard","category-php-wordpress"],"acf":[],"_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":1,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/10986\/revisions"}],"predecessor-version":[{"id":15831,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/10986\/revisions\/15831"}],"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"},{"taxonomy":"group","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/group?post=10986"},{"taxonomy":"pg","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/pg?post=10986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}