{"id":11461,"date":"2026-03-23T23:44:31","date_gmt":"2026-03-23T14:44:31","guid":{"rendered":"https:\/\/code-plus.jp\/gp\/?p=11461"},"modified":"2026-03-25T10:09:44","modified_gmt":"2026-03-25T01:09:44","slug":"wordpress-11461","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/wordpress-11461\/","title":{"rendered":"WordPress\u306e\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u5b8c\u5168\u30ac\u30a4\u30c9\uff5csingle.php\u306e\u7f60\u3068\u30da\u30fc\u30b8\u5225\u5206\u5c90\u306e\u66f8\u304d\u65b9"},"content":{"rendered":"<!-- # WordPress\u306e\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u5b8c\u5168\u30ac\u30a4\u30c9\uff5csingle.php\u306e\u7f60\u3068\u30da\u30fc\u30b8\u5225\u5206\u5c90\u306e\u66f8\u304d\u65b9\r\n<b class=\"bold\">\u30e1\u30bf\u30c7\u30a3\u30b9\u30af\u30ea\u30d7\u30b7\u30e7\u30f3<\/b>\r\nWordPress\u306e\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u306b\u3064\u3044\u3066\u3001\u3088\u304f\u3042\u308b\u8aa4\u89e3\u3068\u6b63\u3057\u3044\u4f7f\u3044\u65b9\u3092\u89e3\u8aac\u3002\u300csingle.php\u306f\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306b\u3082\u9069\u7528\u3055\u308c\u308b\u300d\u306a\u3069\u610f\u5916\u306a\u843d\u3068\u3057\u7a74\u3084\u3001\u6295\u7a3f\u30da\u30fc\u30b8\u30fb\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u30fb\u30a2\u30fc\u30ab\u30a4\u30d6\u3092\u6b63\u78ba\u306b\u5206\u985e\u3059\u308b\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3064\u304d\u3067\u7d39\u4ecb\u3057\u307e\u3059\u3002 -->\r\n<p>WordPress\u306e\u30c6\u30fc\u30de\u958b\u767a\u3067\u3088\u304f\u4f7f\u3046\u300c\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u300d\u3067\u3059\u304c\u3001\u610f\u5916\u3068<b class=\"bold\">\u843d\u3068\u3057\u7a74\u304c\u591a\u3044<\/b>\u3067\u3059\u3002<\/p>\r\n<p>\u7b46\u8005\u3082\u3064\u3044\u6700\u8fd1\u307e\u3067\u52d8\u9055\u3044\u3057\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001<\/p>\r\n<blockquote>\r\n<p><code>is_single()<\/code> \u306f\u901a\u5e38\u306e\u6295\u7a3f\uff08post\uff09\u5c02\u7528\u3060\u3068\u601d\u3063\u3066\u3044\u305f<\/p>\r\n<\/blockquote>\r\n<p>\u5b9f\u306f\u9055\u3044\u307e\u3059\u3002<code>is_single()<\/code> \u306f<b class=\"bold\">\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30bf\u30a4\u30d7\u306b\u3082 true \u3092\u8fd4\u3057\u307e\u3059<\/b>\u3002<\/p>\r\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u300c\u6295\u7a3f\u30da\u30fc\u30b8\u30fb\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u30fb\u305d\u306e\u4ed6\u300d\u306b\u6b63\u78ba\u306b\u5206\u3051\u308b\u305f\u3081\u306e\u66f8\u304d\u65b9\u3092\u3001\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3064\u304d\u3067\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u3088\u304f\u3042\u308b\u8aa4\u89e3\uff1a<code>is_single()<\/code> \u306f\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u3082\u5bfe\u8c61<\/h2>\r\n<p>\u307e\u305a\u6700\u521d\u306b\u78ba\u8a8d\u3057\u3066\u304a\u304d\u305f\u3044\u91cd\u8981\u306a\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">\/\/ \u274c \u3088\u304f\u3042\u308b\u8aa4\u89e3\uff1ais_single() \u306f\u901a\u5e38\u6295\u7a3f\u3060\u3051\u306b\u53cd\u5fdc\u3059\u308b\r\n&lt;?php if (is_single()) : ?&gt;\r\n  &lt;!-- \u901a\u5e38\u6295\u7a3f\u306e\u3064\u3082\u308a\u304c\u3001\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u3067\u3082 true \u306b\u306a\u308b --&gt;\r\n<\/code><\/pre>\r\n<p>WordPress\u306e\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u3088\u308b\u3068\u3001<code>is_single()<\/code> \u306f<b class=\"bold\">\u56fa\u5b9a\u30da\u30fc\u30b8\u3068\u6dfb\u4ed8\u30d5\u30a1\u30a4\u30eb\u4ee5\u5916\u306e\u3001\u4e3b\u8981\u306a\u6295\u7a3f\u30bf\u30a4\u30d7\u306e\u500b\u5225\u30da\u30fc\u30b8<\/b>\u3067 true \u3092\u8fd4\u3057\u307e\u3059\u3002<\/p>\r\n<table class=\"table my-0.5r\">\r\n  <thead>\r\n  <tr class=\"rung\">\r\n    <th>\u6761\u4ef6\u5206\u5c90\u30bf\u30b0<\/th>\r\n    <td align=\"center\">\u901a\u5e38\u6295\u7a3f<\/td>\r\n    <td align=\"center\">\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f<\/td>\r\n    <td align=\"center\">\u56fa\u5b9a\u30da\u30fc\u30b8<\/td>\r\n  <\/tr>\r\n<\/thead><tbody>\r\n<tr class=\"rung\">\r\n  <th><code>is_single()<\/code><\/th>\r\n  <td align=\"center\">\u2705<\/td>\r\n  <td align=\"center\">\u2705<\/td>\r\n  <td align=\"center\">\u274c<\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th><code>is_page()<\/code><\/th>\r\n<td align=\"center\">\u274c<\/td>\r\n<td align=\"center\">\u274c<\/td>\r\n<td align=\"center\">\u2705<\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th><code>is_singular()<\/code><\/th>\r\n<td align=\"center\">\u2705<\/td>\r\n<td align=\"center\">\u2705<\/td>\r\n<td align=\"center\">\u2705<\/td>\r\n<\/tr>\r\n<\/tbody><\/table>\r\n<p>\u3053\u308c\u3092\u77e5\u3089\u305a\u306b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3084CSS\u5206\u5c90\u3092\u66f8\u3044\u3066\u3044\u308b\u3068\u3001\u610f\u56f3\u3057\u306a\u3044\u6319\u52d5\u304c\u8d77\u304d\u307e\u3059\u3002<\/p>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u57fa\u672c\u306e\u5206\u985e\u3068\u6b63\u3057\u3044\u66f8\u304d\u65b9<\/h2>\r\n<p>\u30c6\u30fc\u30de\u958b\u767a\u3067\u3088\u304f\u3042\u308b\u5206\u985e\u306e\u6b63\u3057\u3044\u6761\u4ef6\u5206\u5c90\u306f\u3053\u3046\u66f8\u304d\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php if (is_single() &amp;&amp; get_post_type() === &#39;post&#39;) : ?&gt;\r\n  &lt;!-- 1. \u901a\u5e38\u6295\u7a3f\u30da\u30fc\u30b8\uff08post\uff09\u306e\u307f --&gt;\r\n\r\n&lt;?php elseif (is_singular() &amp;&amp; get_post_type() !== &#39;post&#39; &amp;&amp; !is_page()) : ?&gt;\r\n  &lt;!-- 2. \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306e\u307f\uff08\u901a\u5e38\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u3092\u9664\u304f\uff09 --&gt;\r\n\r\n&lt;?php elseif (is_singular() &amp;&amp; !is_page()) : ?&gt;\r\n &lt;!-- 1&amp;2. \u901a\u5e38\u6295\u7a3f\uff06\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\uff08\u56fa\u5b9a\u30da\u30fc\u30b8\u3092\u9664\u304f\uff09 --&gt;\r\n\r\n&lt;?php elseif (is_page()) : ?&gt;\r\n  &lt;!-- 3. \u56fa\u5b9a\u30da\u30fc\u30b8\u306e\u307f --&gt;\r\n\r\n&lt;?php else : ?&gt;\r\n  &lt;!-- 4. \u305d\u306e\u4ed6\uff08\u30a2\u30fc\u30ab\u30a4\u30d6\u30fb\u30ab\u30c6\u30b4\u30ea\u30fc\u30fb\u30bf\u30b0\u30fb\u691c\u7d22\u7d50\u679c\u306a\u3069\uff09 --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<h3 class=\"fz-ml\">\u306a\u305c <code>get_post_type()<\/code> \u304c\u5fc5\u8981\u306a\u306e\u304b<\/h3>\r\n<p><code>is_single()<\/code> \u3060\u3051\u3067\u306f\u901a\u5e38\u6295\u7a3f\u3068\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u3092\u533a\u5225\u3067\u304d\u306a\u3044\u305f\u3081\u3001<code>get_post_type()<\/code> \u3068\u7d44\u307f\u5408\u308f\u305b\u3066\u6295\u7a3f\u30bf\u30a4\u30d7\u540d\u3067\u7d5e\u308a\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">\/\/ \u901a\u5e38\u6295\u7a3f\u306e\u307f\r\nis_single() &amp;&amp; get_post_type() === &#39;post&#39;\r\n\r\n\/\/ \u7279\u5b9a\u306e\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30bf\u30a4\u30d7\u306e\u307f\r\nis_singular() &amp;&amp; get_post_type() === &#39;bulletin&#39;\r\n\r\n\/\/ \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u5168\u822c\uff08\u901a\u5e38\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u3092\u9664\u304f\uff09\r\nis_singular() &amp;&amp; get_post_type() !== &#39;post&#39; &amp;&amp; !is_page()\r\n<\/code><\/pre>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u3088\u304f\u4f7f\u3046\u6761\u4ef6\u5206\u5c90\u30d1\u30bf\u30fc\u30f3\u96c6<\/h2>\r\n<h3 class=\"fz-ml\">\u30ab\u30c6\u30b4\u30ea\u30fc\u5225\u3067\u5206\u5c90\u3059\u308b<\/h3>\r\n<pre><code class=\"language-php\">&lt;?php if (is_single() &amp;&amp; in_category(&#39;news&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30c6\u30b4\u30ea\u30fc\u300cnews\u300d\u306e\u6295\u7a3f\u30da\u30fc\u30b8 --&gt;\r\n\r\n&lt;?php elseif (is_single() &amp;&amp; in_category(&#39;column&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30c6\u30b4\u30ea\u30fc\u300ccolumn\u300d\u306e\u6295\u7a3f\u30da\u30fc\u30b8 --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<p>\u30b9\u30e9\u30c3\u30b0\u306e\u4ee3\u308f\u308a\u306b\u30ab\u30c6\u30b4\u30ea\u30fcID\u3082\u4f7f\u3048\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php if (is_single() &amp;&amp; in_category(5)) : ?&gt;\r\n<\/code><\/pre>\r\n<h3 class=\"fz-ml\">\u6295\u7a3f\u30bf\u30a4\u30d7\u5225\u3067\u5206\u5c90\u3059\u308b<\/h3>\r\n<pre><code class=\"language-php\">&lt;?php if (is_singular(&#39;bulletin&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u300cbulletin\u300d\u306e\u307f --&gt;\r\n\r\n&lt;?php elseif (is_singular(&#39;news&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u300cnews\u300d\u306e\u307f --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<p><code>is_singular(&#39;post_type_name&#39;)<\/code> \u306f <code>is_singular() &amp;&amp; get_post_type() === &#39;post_type_name&#39;<\/code> \u306e\u77ed\u7e2e\u5f62\u3067\u3059\u3002<\/p>\r\n<h3 class=\"fz-ml\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u5225\u3067\u5206\u5c90\u3059\u308b<\/h3>\r\n<p>\u56fa\u5b9a\u30da\u30fc\u30b8\u3067<b class=\"bold\">\u30ab\u30b9\u30bf\u30e0\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8<\/b>\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u306e\u5206\u5c90\u3067\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php if (is_page_template(&#39;page-contact.php&#39;)) : ?&gt;\r\n  &lt;!-- \u30b3\u30f3\u30bf\u30af\u30c8\u30da\u30fc\u30b8\u5c02\u7528\u306eCSS\u30fbJS\u3092\u8aad\u307f\u8fbc\u3080 --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;fm-contact.css&quot;&gt;\r\n\r\n&lt;?php elseif (is_page_template(&#39;page-about.php&#39;)) : ?&gt;\r\n  &lt;!-- \u4f1a\u793e\u6982\u8981\u30da\u30fc\u30b8 --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<p>\u26a0\ufe0f <code>is_page_template()<\/code> \u306f<b class=\"bold\">\u56fa\u5b9a\u30da\u30fc\u30b8\u5c02\u7528<\/b>\u3067\u3059\u3002\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u3067\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002<\/p>\r\n<h3 class=\"fz-ml\">\u30b9\u30e9\u30c3\u30b0\u5225\u3067\u5206\u5c90\u3059\u308b<\/h3>\r\n<pre><code class=\"language-php\">&lt;?php if (is_page(&#39;privacy-policy&#39;)) : ?&gt;\r\n  &lt;!-- \u30b9\u30e9\u30c3\u30b0\u300cprivacy-policy\u300d\u306e\u56fa\u5b9a\u30da\u30fc\u30b8 --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<p>ID\u3067\u3082\u6307\u5b9a\u3067\u304d\u307e\u3059\uff08\u305f\u3060\u3057\u30b5\u30a4\u30c8\u3092\u307e\u305f\u3044\u3067\u4f7f\u3044\u56de\u3059\u5834\u5408\u306fID\u304c\u5909\u308f\u308b\u305f\u3081\u30b9\u30e9\u30c3\u30b0\u63a8\u5968\uff09\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php if (is_page(42)) : ?&gt;\r\n<\/code><\/pre>\r\n<h3 class=\"fz-ml\">\u30a2\u30fc\u30ab\u30a4\u30d6\u30fb\u4e00\u89a7\u30da\u30fc\u30b8\u3067\u5206\u5c90\u3059\u308b<\/h3>\r\n<pre><code class=\"language-php\">&lt;?php if (is_post_type_archive(&#39;bulletin&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u300cbulletin\u300d\u306e\u30a2\u30fc\u30ab\u30a4\u30d6 --&gt;\r\n\r\n&lt;?php elseif (is_category()) : ?&gt;\r\n  &lt;!-- \u30ab\u30c6\u30b4\u30ea\u30fc\u30a2\u30fc\u30ab\u30a4\u30d6 --&gt;\r\n\r\n&lt;?php elseif (is_tag()) : ?&gt;\r\n  &lt;!-- \u30bf\u30b0\u30a2\u30fc\u30ab\u30a4\u30d6 --&gt;\r\n\r\n&lt;?php elseif (is_tax()) : ?&gt;\r\n  &lt;!-- \u30ab\u30b9\u30bf\u30e0\u30bf\u30af\u30bd\u30ce\u30df\u30fc\u30a2\u30fc\u30ab\u30a4\u30d6 --&gt;\r\n\r\n&lt;?php elseif (is_search()) : ?&gt;\r\n  &lt;!-- \u691c\u7d22\u7d50\u679c\u30da\u30fc\u30b8 --&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8<\/h2>\r\n<h3 class=\"fz-ml\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u2460\uff1aCSS\u5206\u5c90\uff08head.php\u306a\u3069\uff09<\/h3>\r\n<p>\u30da\u30fc\u30b8\u7a2e\u5225\u3054\u3068\u306bCSS\u3092\u8aad\u307f\u5206\u3051\u305f\u3044\u3068\u304d\u306b\u4f7f\u3048\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php if (is_404()) : ?&gt;\r\n  &lt;!-- 404\u30da\u30fc\u30b8\uff08\u6700\u512a\u5148\uff09 --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-404.css&quot;&gt;\r\n\r\n&lt;?php elseif (is_single() &amp;&amp; get_post_type() === &#39;post&#39;) : ?&gt;\r\n  &lt;!-- \u901a\u5e38\u6295\u7a3f\u30da\u30fc\u30b8 --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-single.css&quot;&gt;\r\n\r\n&lt;?php elseif (is_singular(&#39;bulletin&#39;)) : ?&gt;\r\n  &lt;!-- \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u300cbulletin\u300d --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-bulletin.css&quot;&gt;\r\n\r\n&lt;?php elseif (is_singular() &amp;&amp; !is_page() &amp;&amp; get_post_type() !== &#39;post&#39;) : ?&gt;\r\n  &lt;!-- \u305d\u306e\u4ed6\u306e\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-singular.css&quot;&gt;\r\n\r\n&lt;?php elseif (is_front_page() || is_home() || is_page()) : ?&gt;\r\n  &lt;!-- \u56fa\u5b9a\u30da\u30fc\u30b8\u7cfb --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-page.css&quot;&gt;\r\n\r\n  &lt;?php if (is_page_template(&#39;page-contact.php&#39;)) : ?&gt;\r\n    &lt;!-- \u30b3\u30f3\u30bf\u30af\u30c8\u30da\u30fc\u30b8\u8ffd\u52a0CSS --&gt;\r\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;pg-contact.css&quot;&gt;\r\n  &lt;?php endif; ?&gt;\r\n\r\n&lt;?php else : ?&gt;\r\n  &lt;!-- \u30a2\u30fc\u30ab\u30a4\u30d6\u30fb\u30ab\u30c6\u30b4\u30ea\u30fc\u30fb\u30bf\u30b0\u30fb\u691c\u7d22\u7d50\u679c --&gt;\r\n  &lt;link rel=&quot;stylesheet&quot; href=&quot;ly-archive.css&quot;&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<h3 class=\"fz-ml\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u2461\uff1abody ID\u306b\u30b9\u30e9\u30c3\u30b0\u3092\u5272\u308a\u5f53\u3066<\/h3>\r\n<p>CSS\u306e\u30bb\u30ec\u30af\u30bf <code>#page-slug<\/code> \u3067\u30da\u30fc\u30b8\u5225\u30b9\u30bf\u30a4\u30eb\u3092\u5f53\u3066\u308b\u305f\u3081\u306b\u3088\u304f\u4f7f\u3046\u30d1\u30bf\u30fc\u30f3\u3067\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;?php\r\n$body_id = &#39;&#39;;\r\nglobal $post;\r\n\r\nif (is_404()) {\r\n  $body_id = &#39;error-404&#39;;\r\n\r\n} elseif (is_front_page()) {\r\n  $body_id = &#39;front&#39;;\r\n\r\n} elseif (is_home()) {\r\n  $body_id = &#39;home&#39;;\r\n\r\n} elseif (is_singular()) {\r\n  if ($post &amp;&amp; isset($post-&gt;post_name)) {\r\n    $body_id = esc_attr($post-&gt;post_name);\r\n  }\r\n\r\n} elseif (is_post_type_archive()) {\r\n  $body_id = &#39;archive-&#39; . esc_attr(get_post_type());\r\n\r\n} elseif (is_category() || is_tag() || is_tax()) {\r\n  $term = get_queried_object();\r\n  if ($term &amp;&amp; isset($term-&gt;slug)) {\r\n    $body_id = &#39;archive-&#39; . esc_attr($term-&gt;slug);\r\n  }\r\n\r\n} elseif (is_search()) {\r\n  $body_id = &#39;search-results&#39;;\r\n\r\n} else {\r\n  $body_id = &#39;default&#39;;\r\n}\r\n?&gt;\r\n&lt;body id=&quot;&lt;?php echo $body_id; ?&gt;&quot; &lt;?php body_class(); ?&gt;&gt;\r\n<\/code><\/pre>\r\n<h3 class=\"fz-ml\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u2462\uff1a\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u5206\u5c90\uff08functions.php\uff09<\/h3>\r\n<p>\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306b <code>singular.php<\/code> \u3092\u4f7f\u3044\u305f\u3044\u3068\u304d\u3001<code>template_include<\/code> \u30d5\u30a3\u30eb\u30bf\u30fc\u3067\u5236\u5fa1\u3057\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">\/\/ functions.php\r\nfunction my_custom_template_include($template) {\r\n  if (get_post_type() === &#39;post&#39; &amp;&amp; is_single()) {\r\n    \/\/ \u901a\u5e38\u6295\u7a3f \u2192 single.php\r\n    $new_template = locate_template(&lsqb;&#39;single.php&#39;&rsqb;);\r\n    if ($new_template) return $new_template;\r\n\r\n  } elseif (is_singular() &amp;&amp; !is_page() &amp;&amp; get_post_type() !== &#39;post&#39;) {\r\n    \/\/ \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f \u2192 singular.php\r\n    $new_template = locate_template(&lsqb;&#39;singular.php&#39;&rsqb;);\r\n    if ($new_template) return $new_template;\r\n  }\r\n\r\n  return $template;\r\n}\r\nadd_filter(&#39;template_include&#39;, &#39;my_custom_template_include&#39;);\r\n<\/code><\/pre>\r\n<p><code>singular.php<\/code> \u5185\u3067\u3055\u3089\u306b\u6295\u7a3f\u30bf\u30a4\u30d7\u5225\u306b\u5206\u5c90\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">\/\/ singular.php\r\n&lt;?php if (get_post_type() === &#39;bulletin&#39;) : ?&gt;\r\n  &lt;?php get_template_part(&#39;parts\/content&#39;, &#39;bulletin&#39;); ?&gt;\r\n\r\n&lt;?php elseif (get_post_type() === &#39;news&#39;) : ?&gt;\r\n  &lt;?php get_template_part(&#39;parts\/content&#39;, &#39;news&#39;); ?&gt;\r\n\r\n&lt;?php endif; ?&gt;\r\n<\/code><\/pre>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u968e\u5c64\u3068\u6761\u4ef6\u5206\u5c90\u306e\u95a2\u4fc2\u307e\u3068\u3081<\/h2>\r\n<p>WordPress\u304c\u3069\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u304b\u306f<b class=\"bold\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u968e\u5c64<\/b>\u3067\u6c7a\u307e\u308a\u307e\u3059\u3002\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u306f\u305d\u306e\u30d5\u30a1\u30a4\u30eb\u5185\u3067\u306e\u51e6\u7406\u5206\u5c90\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-\">\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u30d5\u30a1\u30a4\u30eb\uff08WordPress \u304c\u81ea\u52d5\u9078\u629e\uff09\r\n\u2514\u2500 \u500b\u5225\u8868\u793a\r\n    \u251c\u2500 single-{post_type}.php  \u2190 \u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u5c02\u7528\u3092\u4f5c\u308b\u306a\u3089\u3053\u3053\r\n    \u251c\u2500 single.php              \u2190 \u901a\u5e38\u6295\u7a3f\uff06\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306e\u5171\u901a\r\n    \u251c\u2500 singular.php            \u2190 \u4e0a\u8a18\u304c\u306a\u3044\u5834\u5408\u306e\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\r\n    \u2514\u2500 index.php\r\n\r\n\u2514\u2500 \u56fa\u5b9a\u30da\u30fc\u30b8\r\n    \u251c\u2500 \u30ab\u30b9\u30bf\u30e0\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8.php\r\n    \u251c\u2500 page-{slug}.php\r\n    \u251c\u2500 page.php\r\n    \u2514\u2500 singular.php\r\n\r\n\u2514\u2500 \u30a2\u30fc\u30ab\u30a4\u30d6\r\n    \u251c\u2500 archive-{post_type}.php\r\n    \u251c\u2500 category.php \/ tag.php\r\n    \u251c\u2500 archive.php\r\n    \u2514\u2500 index.php               \u2190 search.php \u306f\u3053\u3053\u306b\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\uff08archive.php \u3067\u306f\u306a\u3044\uff09\r\n<\/code><\/pre>\r\n<p><b class=\"bold\">\u6ce8\u610f\u70b9<\/b>\uff1a<code>search.php<\/code> \u306f <code>archive.php<\/code> \u306b\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u3057\u307e\u305b\u3093\u3002<code>search.php<\/code> \u2192 <code>index.php<\/code> \u306e\u9806\u3067\u3059\u3002\u691c\u7d22\u7d50\u679c\u30da\u30fc\u30b8\u306e\u30ec\u30a4\u30a2\u30a6\u30c8\u306f\u30ab\u30c6\u30b4\u30ea\u30fc\u30da\u30fc\u30b8\u3068\u4f3c\u3066\u3044\u3066\u3082\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306f\u72ec\u7acb\u3057\u3066\u4f5c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\r\n<hr class=\"separator mt-3r\">\r\n<h2 class=\"fz-xl\">\u307e\u3068\u3081<\/h2>\r\n<table class=\"table my-0.5r\">\r\n  <thead>\r\n  <tr class=\"rung\">\r\n    <th>\u3084\u308a\u305f\u3044\u3053\u3068<\/th>\r\n    <td>\u6b63\u3057\u3044\u66f8\u304d\u65b9<\/td>\r\n  <\/tr>\r\n<\/thead><tbody>\r\n<tr class=\"rung\">\r\n  <th>\u901a\u5e38\u6295\u7a3f\u306e\u307f<\/th>\r\n  <td><code>is_single() &amp;&amp; get_post_type() === &#39;post&#39;<\/code><\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306e\u307f<\/th>\r\n<td><code>is_singular() &amp;&amp; !is_page() &amp;&amp; get_post_type() !== &#39;post&#39;<\/code><\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>\u7279\u5b9a\u306e\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306e\u307f<\/th>\r\n<td><code>is_singular(&#39;post_type_name&#39;)<\/code><\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>\u56fa\u5b9a\u30da\u30fc\u30b8\u306e\u307f<\/th>\r\n<td><code>is_page()<\/code><\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>\u7279\u5b9a\u306e\u56fa\u5b9a\u30da\u30fc\u30b8<\/th>\r\n<td><code>is_page(&#39;slug&#39;)<\/code><\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>\u30ab\u30b9\u30bf\u30e0\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8<\/th>\r\n<td><code>is_page_template(&#39;template.php&#39;)<\/code> \u203b\u56fa\u5b9a\u30da\u30fc\u30b8\u306e\u307f<\/td>\r\n<\/tr><tr class=\"rung\">\r\n<th>404\u30da\u30fc\u30b8<\/th>\r\n<td><code>is_404()<\/code> \u3092\u6700\u512a\u5148\u3067\u66f8\u304f<\/td>\r\n<\/tr>\r\n<\/tbody><\/table>\r\n<p><code>is_single()<\/code> \u304c\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306b\u3082\u53cd\u5fdc\u3059\u308b\u3068\u3044\u3046\u4ed5\u69d8\u3092\u77e5\u3063\u3066\u3044\u308b\u3060\u3051\u3067\u3001\u30c6\u30fc\u30de\u958b\u767a\u306e\u591a\u304f\u306e\u300c\u306a\u305c\u304b\u52d5\u304b\u306a\u3044\u300d\u3092\u9632\u3052\u307e\u3059\u3002\u305c\u3072\u3053\u306e\u8a18\u4e8b\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u30d9\u30fc\u30b9\u306b\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>","protected":false},"excerpt":{"rendered":"WordPress\u306e\u6761\u4ef6\u5206\u5c90\u30bf\u30b0\u306b\u3064\u3044\u3066\u3001\u3088\u304f\u3042\u308b\u8aa4\u89e3\u3068\u6b63\u3057\u3044\u4f7f\u3044\u65b9\u3092\u89e3\u8aac\u3002\u300csingle.php\u306f\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u306b\u3082\u9069\u7528\u3055\u308c\u308b\u300d\u306a\u3069\u610f\u5916\u306a\u843d\u3068\u3057\u7a74\u3084\u3001\u6295\u7a3f\u30da\u30fc\u30b8\u30fb\u30ab\u30b9\u30bf\u30e0\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u30fb\u30a2\u30fc\u30ab\u30a4\u30d6\u3092\u6b63\u78ba\u306b\u5206\u985e\u3059\u308b\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30da\u3067\u4f7f\u3048\u308b\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3064\u304d\u3067\u7d39\u4ecb\u3057\u307e\u3059\u3002","protected":false},"author":1,"featured_media":11475,"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-11461","post","type-post","status-publish","format-standard","has-post-thumbnail","category-wordpress"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/11461","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=11461"}],"version-history":[{"count":0,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/11461\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media\/11475"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=11461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=11461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=11461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}