{"id":9125,"date":"2025-09-25T12:57:48","date_gmt":"2025-09-25T03:57:48","guid":{"rendered":"https:\/\/code-plus.jp\/gp\/?p=9125"},"modified":"2026-01-08T11:17:22","modified_gmt":"2026-01-08T02:17:22","slug":"toc-category-9125","status":"publish","type":"post","link":"https:\/\/code-plus.jp\/gp\/toc-category-9125\/","title":{"rendered":"\u3010WordPress\u3011\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u8a18\u4e8b\u306e\u76ee\u6b21\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u308b\u30ab\u30b9\u30bf\u30de\u30a4\u30ba"},"content":{"rendered":"<p>WordPress\u30b5\u30a4\u30c8\u3067\u8a18\u4e8b\u3092\u8aad\u3093\u3067\u3044\u308b\u3068\u304d\u3001\u300c\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6b21\u306e\u8a18\u4e8b\u306b\u3059\u3050\u79fb\u52d5\u3057\u305f\u3044\u300d\u3068\u601d\u3063\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u304b\uff1f<\/p>\r\n<p>\u4e00\u822c\u7684\u306aWordPress\u30b5\u30a4\u30c8\u3067\u306f\u300c\u6700\u8fd1\u306e\u6295\u7a3f\u300d\u3084\u300c\u30ab\u30c6\u30b4\u30ea\u30fc\u4e00\u89a7\u300d\u304c\u30b5\u30a4\u30c9\u30d0\u30fc\u306b\u8868\u793a\u3055\u308c\u307e\u3059\u304c\u3001\u3053\u308c\u3089\u306f\u73fe\u5728\u8aad\u3093\u3067\u3044\u308b\u8a18\u4e8b\u3068\u306e\u95a2\u9023\u6027\u304c\u8584\u304f\u3001\u8aad\u8005\u306e\u56de\u904a\u7387\u5411\u4e0a\u306b\u306f\u3042\u307e\u308a\u52b9\u679c\u7684\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\r\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001<b class=\"fw-600\">\u73fe\u5728\u306e\u8a18\u4e8b\u3092\u542b\u3081\u3066\u540c\u4e00\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u9023\u7d9a\u3059\u308b\u8a18\u4e8b\u3092\u30b5\u30a4\u30c9\u30d0\u30fc\u306b\u8868\u793a\u3059\u308b<\/b><br class=\"d-none_sp\" \/>\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u65b9\u6cd5\u30922\u30d1\u30bf\u30fc\u30f3\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\r\n\r\n <!-- \u2605\u76ee\u6b21\u30ea\u30b9\u30c8 -->\r\n<nav class=\"toc-container mt-2r\">\r\n  <ul class=\"toc-list\" data-toc-id=\"js-tocBWGD\"><\/ul>\r\n<\/nav>\r\n\r\n<script src=\"https:\/\/www.code-plus.jp\/cdn\/js\/_gimmicks\/inppend-toc.js\"><\/script>\r\n\r\n\r\n\r\n\r\n\r\n\r\n<h2 class=\"fz-xl\">\u5b8c\u6210\u30a4\u30e1\u30fc\u30b8<\/h2>\r\n<p>\u5b9f\u88c5\u5f8c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\uff1a<\/p>\r\n\r\n<picture class=\"bd-bounds\" style=\"width:100%;\">\r\n  <img decoding=\"async\" src=\"https:\/\/code-plus.jp\/gp\/wp-content\/uploads\/SS-2025-09-25-14.02.14.png\" alt=\"\" width=\"1219\" height=\"626\" class=\"alignnone size-full wp-image-9131\" \/>\r\n<\/picture>\r\n\r\n\r\n\r\n<h3 class=\"fz-ml\">\u30d1\u30bf\u30fc\u30f31\uff1a\u9023\u7d9a\u8a18\u4e8b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\uff08tocCat.php\uff09<\/h3>\r\n<ul style=\"list-style-type:bullet;\">\r\n  <li><b class=\"fw-600\">\u73fe\u5728\u8aad\u3093\u3067\u3044\u308b\u8a18\u4e8b\uff08\u30cf\u30a4\u30e9\u30a4\u30c8\u8868\u793a\uff09<\/b><\/li>\r\n  <li>\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6b21\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6b21\u306e\u6b21\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6b21\u306e\u6b21\u306e\u6b21\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u6b21\u306e\u6b21\u306e\u6b21\u306e\u6b21\u306e\u8a18\u4e8b<\/li>\r\n<\/ul>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u30d1\u30bf\u30fc\u30f32\uff1a\u30ab\u30c6\u30b4\u30ea\u30fc\u8a18\u4e8b\u30ea\u30b9\u30c8\uff08postList.php\uff09<\/h3>\r\n<ul style=\"list-style-type:bullet;\">\r\n  <li>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e1\u756a\u76ee\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e2\u756a\u76ee\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e3\u756a\u76ee\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e4\u756a\u76ee\u306e\u8a18\u4e8b<\/li>\r\n  <li>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e5\u756a\u76ee\u306e\u8a18\u4e8b\uff08\u73fe\u5728\u306e\u8a18\u4e8b\u304c\u542b\u307e\u308c\u308b\u5834\u5408\u306f\u30cf\u30a4\u30e9\u30a4\u30c8\uff09<\/li>\r\n<\/ul>\r\n<p>\u3053\u308c\u306b\u3088\u308a\u8aad\u8005\u306f\u8ff7\u3046\u3053\u3068\u306a\u304f\u3001\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u8a18\u4e8b\u3092\u52b9\u7387\u7684\u306b\u8aad\u307f\u9032\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u5b9f\u88c5\u624b\u9806<\/h2>\r\n\r\n\r\n<h3 class=\"fz-ml\">1. \u9023\u7d9a\u8a18\u4e8b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\uff08tocCat.php\uff09\u306e\u4f5c\u6210<\/h3>\r\n<p>\u73fe\u5728\u306e\u8a18\u4e8b\u3092\u57fa\u6e96\u306b\u3057\u305f\u524d\u5f8c\u306e\u8a18\u4e8b\u3092\u8868\u793a\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\r\n<p><code>\/wp-content\/themes\/your-theme\/parts\/toc\/tocCat.php<\/code><\/p>\r\n<pre><code class=\"language-php\">&lt;?php\r\n\/**\r\n* tocCat-desc.php\uff08\u30ab\u30c6\u30b4\u30ea\u30fc\u5225\u306e\u8a18\u4e8b\u76ee\u6b21\uff09\r\n* \u73fe\u5728\u306e\u8a18\u4e8b\u3092\u542b\u3081\u3066\u3001\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u6b21\u306e\u8a18\u4e8b\u3092\u8868\u793a\r\n*\/\r\n?&gt;\r\n&lt;script&gt;\r\n(function() {\r\nconst STYLE = document.createElement(&#39;style&#39;);\r\nSTYLE.textContent = `\r\n\/* CSS\uff08\u7701\u7565\u3001\u8a73\u7d30\u306f\u5f8c\u8ff0\uff09 *\/\r\n`;\r\ndocument.getElementsByTagName(&#39;head&#39;)[0].appendChild(STYLE);\r\n})();\r\n&lt;\/script&gt;\r\n&lt;?php\r\n\/\/\u73fe\u5728\u306e\u8a18\u4e8b\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u60c5\u5831\u3092\u53d6\u5f97\r\nif (has_category()) {\r\n  $categories = get_the_category();\r\n  if (!empty($categories)) {\r\n    $category = $categories[0];\r\n    $cat_id   = $category-&gt;cat_ID;\r\n    $cat_name = $category-&gt;cat_name;\r\n    $current_post_id = get_the_ID();\r\n    \r\n    \/\/\u307e\u305amenu_order\u3067\u4e26\u3073\u9806\u3092\u30c1\u30a7\u30c3\u30af\r\n    $args_menu_order = array(\r\n      &#39;cat&#39; =&gt; $cat_id,\r\n      &#39;posts_per_page&#39; =&gt; -1,\r\n      &#39;orderby&#39; =&gt; &#39;menu_order&#39;,\r\n      &#39;order&#39; =&gt; &#39;DESC&#39;,\r\n      &#39;post_status&#39; =&gt; &#39;publish&#39;\r\n    );\r\n    \r\n    $posts_by_menu_order = get_posts($args_menu_order);\r\n    \r\n    \/\/menu_order\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\r\n    $has_menu_order = false;\r\n    foreach ($posts_by_menu_order as $post) {\r\n      if ($post-&gt;menu_order != 0) {\r\n        $has_menu_order = true;\r\n        break;\r\n      }\r\n    }\r\n    \r\n    \/\/menu_order\u304c\u306a\u3044\u5834\u5408\u306f\u6295\u7a3f\u65e5\u3067\u4e26\u3073\u66ff\u3048\r\n    if (!$has_menu_order) {\r\n      $args_date = array(\r\n        &#39;cat&#39; =&gt; $cat_id,\r\n        &#39;posts_per_page&#39; =&gt; -1,\r\n        &#39;orderby&#39; =&gt; &#39;date&#39;,\r\n        &#39;order&#39; =&gt; &#39;DESC&#39;,\r\n        &#39;post_status&#39; =&gt; &#39;publish&#39;\r\n      );\r\n      $all_posts = get_posts($args_date);\r\n    } else {\r\n      $all_posts = $posts_by_menu_order;\r\n    }\r\n    \r\n    if (!empty($all_posts)) {\r\n      \/\/\u73fe\u5728\u306e\u8a18\u4e8b\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u53d6\u5f97\r\n      $current_index = -1;\r\n      foreach ($all_posts as $index =&gt; $post) {\r\n        if ($post-&gt;ID == $current_post_id) {\r\n          $current_index = $index;\r\n          break;\r\n        }\r\n      }\r\n      \r\n      if ($current_index === -1) {\r\n        return;\r\n      }\r\n      \r\n      \/\/\u73fe\u5728\u306e\u8a18\u4e8b\u304b\u3089\u6b21\u306e\u8a18\u4e8b\u30925\u4ef6\u62bd\u51fa\uff08\u73fe\u5728\u306e\u8a18\u4e8b + \u6b21\u306e4\u4ef6\uff09\r\n      $display_posts = array();\r\n      \r\n      for ($i = 0; $i &lt; 5; $i++) {\r\n        $post_index = $current_index - $i;  \/\/\u30de\u30a4\u30ca\u30b9\u65b9\u5411\u306b\u79fb\u52d5\r\n        if ($post_index &gt;= 0 &amp;&amp; isset($all_posts[$post_index])) {\r\n          $display_posts[] = $all_posts[$post_index];\r\n        }\r\n      }\r\n      \r\n      if (!empty($display_posts)) {\r\n?&gt;\r\n\r\n&lt;div class=&quot;widget-saraTocCat_Side&quot;&gt;\r\n  &lt;div class=&quot;tocCat-veu&quot;&gt;\r\n    &lt;h2 class=&quot;widgettitle&quot;&gt;&lt;?php echo esc_html($cat_name); ?&gt;&lt;\/h2&gt;\r\n\r\n    &lt;ul class=&quot;tocCat-list&quot;&gt;\r\n      &lt;?php foreach ($display_posts as $index =&gt; $post) : setup_postdata($post); ?&gt;\r\n      &lt;?php \r\n      \/\/\u73fe\u5728\u306e\u8a18\u4e8b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\r\n      $is_current = ($post-&gt;ID == $current_post_id);\r\n      $current_class = $is_current ? &#39; current_page_item&#39; : &#39;&#39;;\r\n      \r\n      \/\/\u30bf\u30a4\u30c8\u30eb\u306e\u6587\u5b57\u6570\u5236\u9650\r\n      $title = get_the_title($post-&gt;ID);\r\n      $title_length_limit = 45;\r\n      $display_title = mb_strlen($title) &gt; $title_length_limit \r\n        ? mb_substr($title, 0, $title_length_limit) . &#39;...&#39; \r\n        : $title;\r\n      ?&gt;\r\n      &lt;li class=&quot;tocCat-item&lt;?php echo $current_class; ?&gt;&quot; id=&quot;post-&lt;?php echo $post-&gt;ID; ?&gt;&quot;&gt;\r\n        &lt;a class=&quot;fl-left&quot; href=&quot;&lt;?php echo get_permalink($post-&gt;ID); ?&gt;&quot;&gt;\r\n          &lt;picture class=&quot;tocCat-thumbnail&quot;&gt;\r\n            &lt;?php \r\n            $thumbnail = get_the_post_thumbnail($post-&gt;ID, array(96, 96));\r\n            if ($thumbnail) {\r\n              echo $thumbnail;\r\n            } else {\r\n              echo &#39;&lt;img src=&quot;&#39; . get_theme_file_path() . &#39;\/img\/noimage.png&quot; alt=&quot;&#39; . esc_attr($title) . &#39;&quot;&gt;&#39;;\r\n            }\r\n            ?&gt;\r\n          &lt;\/picture&gt;\r\n        &lt;\/a&gt;\r\n        &lt;div class=&quot;tocCat-content&quot;&gt;\r\n          &lt;h4 class=&quot;tocCat-title&quot;&gt;\r\n            &lt;a href=&quot;&lt;?php echo get_permalink($post-&gt;ID); ?&gt;&quot; title=&quot;&lt;?php echo esc_attr($title); ?&gt;&quot;&gt;&lt;?php echo esc_html($display_title); ?&gt;&lt;\/a&gt;\r\n          &lt;\/h4&gt;\r\n          &lt;span class=&quot;tocCat-date&quot;&gt;&lt;?php echo get_the_date(&#39;Y.m.d&#39;, $post-&gt;ID); ?&gt;&lt;\/span&gt;\r\n        &lt;\/div&gt;\r\n      &lt;\/li&gt;\r\n      &lt;?php endforeach; ?&gt;\r\n      &lt;?php wp_reset_postdata(); ?&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;?php\r\n      }\r\n    }\r\n  }\r\n}\r\n?&gt;\r\n<\/code><\/pre>\r\n\r\n\r\n<h3 class=\"fz-ml\">2. \u30ab\u30c6\u30b4\u30ea\u30fc\u8a18\u4e8b\u30ea\u30b9\u30c8\uff08postList.php\uff09\u306e\u4f5c\u6210<\/h3>\r\n<p>\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u4e0a\u4f4d\u8a18\u4e8b\u3092\u8868\u793a\u3059\u308b\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\r\n<p><code>\/wp-content\/themes\/your-theme\/parts\/list\/postList.php<\/code><\/p>\r\n<pre><code class=\"language-php\">&lt;?php\r\n\/**\r\n * \u30ab\u30c6\u30b4\u30ea\u30fc\u8a18\u4e8b\u30ea\u30b9\u30c8\r\n * \u73fe\u5728\u306e\u8a18\u4e8b\u3068\u540c\u3058\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u4e0a\u4f4d5\u4ef6\u3092\u8868\u793a\r\n *\/\r\n?&gt;\r\n&lt;script&gt;\r\n(function() {\r\nconst STYLE = document.createElement(&#39;style&#39;);\r\nSTYLE.textContent = `\r\n\/* postList\u7528CSS\uff08tocCat\u3068\u540c\u69d8\u306e\u69cb\u9020\u3067\u30af\u30e9\u30b9\u540d\u3092\u5909\u66f4\uff09 *\/\r\n`;\r\ndocument.getElementsByTagName(&#39;head&#39;)[0].appendChild(STYLE);\r\n})();\r\n&lt;\/script&gt;\r\n&lt;?php\r\n\/\/\u73fe\u5728\u306e\u8a18\u4e8b\u306e\u30ab\u30c6\u30b4\u30ea\u30fc\u60c5\u5831\u3092\u53d6\u5f97\r\nif (has_category()) {\r\n  $categories = get_the_category();\r\n  if (!empty($categories)) {\r\n    $category = $categories[0];\r\n    $cat_id   = $category-&gt;cat_ID;\r\n    $cat_name = $category-&gt;cat_name;\r\n    $current_post_id = get_the_ID();\r\n    \r\n    \/\/menu_order\u30c1\u30a7\u30c3\u30af\u3068\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\uff08tocCat\u3068\u540c\u69d8\uff09\r\n    \/\/...\r\n    \r\n    \/\/\u4e0a\u4f4d5\u4ef6\u306e\u307f\u53d6\u5f97\r\n    if (!$has_menu_order) {\r\n      $args_date = array(\r\n        &#39;cat&#39; =&gt; $cat_id,\r\n        &#39;posts_per_page&#39; =&gt; 5, \/\/5\u4ef6\u306e\u307f\u53d6\u5f97\r\n        &#39;orderby&#39; =&gt; &#39;date&#39;,\r\n        &#39;order&#39; =&gt; &#39;DESC&#39;,\r\n        &#39;post_status&#39; =&gt; &#39;publish&#39;\r\n      );\r\n      $postlist_posts = get_posts($args_date);\r\n    } else {\r\n      \/\/menu_order\u304c\u3042\u308b\u5834\u5408\u306f\u4e0a\u4f4d5\u4ef6\u3092\u53d6\u5f97\r\n      $postlist_posts = array_slice($posts_by_menu_order, 0, 5);\r\n    }\r\n    \r\n    if (!empty($postlist_posts)) {\r\n?&gt;\r\n\r\n&lt;div class=&quot;widget-saraPostList_Side&quot;&gt;\r\n  &lt;div class=&quot;postList-veu&quot;&gt;\r\n    &lt;h2 class=&quot;widgettitle&quot;&gt;&lt;?php echo esc_html($cat_name); ?&gt;&lt;\/h2&gt;\r\n\r\n    &lt;ul class=&quot;postList-list&quot;&gt;\r\n      &lt;?php foreach ($postlist_posts as $index =&gt; $post) : setup_postdata($post); ?&gt;\r\n      &lt;?php \r\n      \/\/\u73fe\u5728\u306e\u8a18\u4e8b\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\r\n      $is_current = ($post-&gt;ID == $current_post_id);\r\n      $current_class = $is_current ? &#39; current_page_item&#39; : &#39;&#39;;\r\n      \r\n      \/\/\u30bf\u30a4\u30c8\u30eb\u306e\u6587\u5b57\u6570\u5236\u9650\uff08\u540c\u69d8\u306e\u51e6\u7406\uff09\r\n      ?&gt;\r\n      &lt;li class=&quot;postList-item&lt;?php echo $current_class; ?&gt;&quot; id=&quot;post-&lt;?php echo $post-&gt;ID; ?&gt;&quot;&gt;\r\n        &lt;!-- HTML\u69cb\u9020\u306ftocCat\u3068\u540c\u69d8\u3001\u30af\u30e9\u30b9\u540d\u306e\u307f\u5909\u66f4 --&gt;\r\n      &lt;\/li&gt;\r\n      &lt;?php endforeach; ?&gt;\r\n      &lt;?php wp_reset_postdata(); ?&gt;\r\n    &lt;\/ul&gt;\r\n  &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n\r\n&lt;?php\r\n    }\r\n  }\r\n}\r\n?&gt;\r\n<\/code><\/pre>\r\n\r\n\r\n<h3 class=\"fz-ml\">3. single.php\u3067\u306e\u8aad\u307f\u8fbc\u307f<\/h3>\r\n<p>\u6295\u7a3f\u30da\u30fc\u30b8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3067\u4f5c\u6210\u3057\u305fPHP\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\r\n<pre><code class=\"language-php\">&lt;!-- \u30b5\u30a4\u30c9\u30d0\u30fc --&gt;\r\n&lt;aside class=&quot;flanker flanker4efA&quot;&gt;\r\n  &lt;!-- \u30d1\u30bf\u30fc\u30f31\uff1a\u9023\u7d9a\u8a18\u4e8b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3 --&gt;\r\n  &lt;?php include(get_theme_file_path() . &#39;\/parts\/toc\/tocCat.php&#39;); ?&gt;\r\n  \r\n  &lt;!-- \u307e\u305f\u306f --&gt;\r\n  \r\n  &lt;!-- \u30d1\u30bf\u30fc\u30f32\uff1a\u30ab\u30c6\u30b4\u30ea\u30fc\u8a18\u4e8b\u30ea\u30b9\u30c8 --&gt;\r\n  &lt;?php include(get_theme_file_path() . &#39;\/parts\/list\/postList.php&#39;); ?&gt;\r\n&lt;\/aside&gt;\r\n<\/code><\/pre>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u30b3\u30fc\u30c9\u306e\u89e3\u8aac<\/h2>\r\n\r\n\r\n<h3 class=\"fz-ml\">tocCat.php\u306e\u7279\u5fb4<\/h3>\r\n<h4 class=\"fz-md\">1. \u73fe\u5728\u8a18\u4e8b\u3092\u57fa\u6e96\u306b\u3057\u305f\u53d6\u5f97<\/h4>\r\n<pre><code class=\"language-php\">\/\/\u73fe\u5728\u306e\u8a18\u4e8b\u304b\u3089\u6b21\u306e\u8a18\u4e8b\u30925\u4ef6\u62bd\u51fa\r\nfor ($i = 0; $i &lt; 5; $i++) {\r\n  $post_index = $current_index - $i;  \/\/\u30de\u30a4\u30ca\u30b9\u65b9\u5411\u306b\u79fb\u52d5\r\n  if ($post_index &gt;= 0 &amp;&amp; isset($all_posts[$post_index])) {\r\n    $display_posts[] = $all_posts[$post_index];\r\n  }\r\n}\r\n<\/code><\/pre>\r\n\r\n<h3 class=\"fz-ml\">postList.php\u306e\u7279\u5fb4<\/h3>\r\n<h4 class=\"fz-md\">1. \u30b7\u30f3\u30d7\u30eb\u306a\u4e0a\u4f4d\u8a18\u4e8b\u53d6\u5f97<\/h4>\r\n<pre><code class=\"language-php\">if (!$has_menu_order) {\r\n  $args_date = array(\r\n    &#39;cat&#39; =&gt; $cat_id,\r\n    &#39;posts_per_page&#39; =&gt; 5, \/\/\u6700\u521d\u304b\u30895\u4ef6\u306e\u307f\u53d6\u5f97\r\n    &#39;orderby&#39; =&gt; &#39;date&#39;,\r\n    &#39;order&#39; =&gt; &#39;DESC&#39;,\r\n    &#39;post_status&#39; =&gt; &#39;publish&#39;\r\n  );\r\n  $postlist_posts = get_posts($args_date);\r\n} else {\r\n  \/\/menu_order\u304c\u3042\u308b\u5834\u5408\u306f\u914d\u5217\u306e\u5148\u982d5\u4ef6\u3092\u5207\u308a\u51fa\u3057\r\n  $postlist_posts = array_slice($posts_by_menu_order, 0, 5);\r\n}\r\n<\/code><\/pre>\r\n<h4 class=\"fz-md\">2. \u73fe\u5728\u8a18\u4e8b\u306e\u30cf\u30a4\u30e9\u30a4\u30c8\u6a5f\u80fd<\/h4>\r\n<p>\u73fe\u5728\u306e\u8a18\u4e8b\u304c\u30ea\u30b9\u30c8\u306b\u542b\u307e\u308c\u308b\u5834\u5408\u3001\u81ea\u52d5\u7684\u306b <code>current_page_item<\/code> \u30af\u30e9\u30b9\u304c\u4ed8\u4e0e\u3055\u308c\u3001\u8996\u899a\u7684\u306b\u533a\u5225\u3055\u308c\u307e\u3059\u3002<\/p>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u5171\u901a\u306e\u4e26\u3073\u9806\u5236\u5fa1<\/h3>\r\n<p>\u4e21\u65b9\u306e\u30d5\u30a1\u30a4\u30eb\u3067\u4ee5\u4e0b\u306e\u512a\u5148\u9806\u4f4d\u3067\u4e26\u3073\u9806\u3092\u6c7a\u5b9a\u3057\u307e\u3059\uff1a<\/p>\r\n<ol style=\"list-style-type:decimal;\">\r\n  <li><b class=\"fw-600\">menu_order<\/b>\uff08\u30ab\u30b9\u30bf\u30e0\u30aa\u30fc\u30c0\u30fc\uff09- \u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u5834\u5408<\/li>\r\n  <li><b class=\"fw-600\">\u6295\u7a3f\u65e5\uff08\u6607\u9806\uff09<\/b>- menu_order\u304c\u672a\u8a2d\u5b9a\u306e\u5834\u5408\u306e\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af<\/li>\r\n<\/ol>\r\n<pre><code class=\"language-php\">\/\/menu_order\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u304b\u30c1\u30a7\u30c3\u30af\r\n$has_menu_order = false;\r\nforeach ($posts_by_menu_order as $post) {\r\n  if ($post-&gt;menu_order != 0) {\r\n    $has_menu_order = true;\r\n    break;\r\n  }\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n<h2 class=\"fz-xl\">CSS\u30b9\u30bf\u30a4\u30ea\u30f3\u30b0\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u30db\u30d0\u30fc\u52b9\u679c\uff08\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u52d5\u304b\u306a\u3044\u5de6\u30dc\u30fc\u30c0\u30fc\uff09<\/h3>\r\n<pre><code class=\"language-css\">.widget-saraTocCat_Side .tocCat-veu .tocCat-list .tocCat-item {\r\n  box-shadow: 5px 0 0 0 transparent inset;\r\n  transition: box-shadow 0.3s ease-out;\r\n}\r\n\r\n.widget-saraTocCat_Side .tocCat-veu .tocCat-list .tocCat-item:has(:is([href], [onclick]):hover) {\r\n  box-shadow: 5px 0 0 0 var(--c-secondary-200, hsl(223, 39%, 53%)) inset;\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u73fe\u5728\u8a18\u4e8b\u306e\u30cf\u30a4\u30e9\u30a4\u30c8<\/h3>\r\n<pre><code class=\"language-css\">.widget-saraTocCat_Side .tocCat-veu .tocCat-list .tocCat-item.current_page_item {\r\n  box-shadow: 5px 0 0 0 var(--c-secondary-400, hsl(223, 39%, 63%)) inset;\r\n}\r\n<\/code><\/pre>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u4f7f\u3044\u5206\u3051\u306e\u30ac\u30a4\u30c9\u30e9\u30a4\u30f3<\/h2>\r\n\r\n\r\n<h3 class=\"fz-ml\">tocCat.php\uff08\u9023\u7d9a\u8a18\u4e8b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\uff09\u304c\u9069\u3057\u3066\u3044\u308b\u5834\u5408<\/h3>\r\n<ul style=\"list-style-type:bullet;\">\r\n  <li><b class=\"fw-600\">\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u30b5\u30a4\u30c8<\/b>: \u9023\u7d9a\u3057\u305f\u5b66\u7fd2\u30b3\u30f3\u30c6\u30f3\u30c4<\/li>\r\n  <li><b class=\"fw-600\">\u30b7\u30ea\u30fc\u30ba\u8a18\u4e8b<\/b>: \u9806\u5e8f\u901a\u308a\u306b\u8aad\u3093\u3067\u307b\u3057\u3044\u8a18\u4e8b\u7fa4<\/li>\r\n  <li><b class=\"fw-600\">\u30b9\u30c8\u30fc\u30ea\u30fc\u6027\u306e\u3042\u308b\u30d6\u30ed\u30b0<\/b>: \u524d\u5f8c\u306e\u6587\u8108\u304c\u91cd\u8981\u306a\u8a18\u4e8b<\/li>\r\n<\/ul>\r\n\r\n\r\n<h3 class=\"fz-ml\">postList.php\uff08\u30ab\u30c6\u30b4\u30ea\u30fc\u8a18\u4e8b\u30ea\u30b9\u30c8\uff09\u304c\u9069\u3057\u3066\u3044\u308b\u5834\u5408<\/h3>\r\n<ul style=\"list-style-type:bullet;\">\r\n  <li><b class=\"fw-600\">\u4e00\u822c\u7684\u306a\u30d6\u30ed\u30b0\u30b5\u30a4\u30c8<\/b>: \u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u8a18\u4e8b\u6982\u89b3\u3092\u63d0\u4f9b<\/li>\r\n  <li><b class=\"fw-600\">\u30cb\u30e5\u30fc\u30b9\u30b5\u30a4\u30c8<\/b>: \u6700\u65b0\u8a18\u4e8b\u3084\u4eba\u6c17\u8a18\u4e8b\u306e\u8868\u793a<\/li>\r\n  <li><b class=\"fw-600\">\u30dd\u30fc\u30c8\u30d5\u30a9\u30ea\u30aa\u30b5\u30a4\u30c8<\/b>: \u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u4ee3\u8868\u7684\u306a\u4f5c\u54c1\u8868\u793a<\/li>\r\n<\/ul>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u30aa\u30d7\u30b7\u30e7\u30f3<\/h2>\r\n\r\n<h3 class=\"fz-ml\">\u6587\u5b57\u6570\u5236\u9650\u306e\u8abf\u6574<\/h3>\r\n<pre><code class=\"language-php\">$title_length_limit = 45; \/\/45\u6587\u5b57\u3092\u4efb\u610f\u306e\u6587\u5b57\u6570\u306b\u5909\u66f4\r\n<\/code><\/pre>\r\n\r\n<h3 class=\"fz-ml\">\u8868\u793a\u4ef6\u6570\u306e\u5909\u66f4<\/h3>\r\n<pre><code class=\"language-php\">\/\/tocCat.php\r\nfor ($i = 0; $i &lt; 5; $i++) { \/\/5\u3092\u4efb\u610f\u306e\u6570\u5b57\u306b\u5909\u66f4\r\n\r\n\/\/postList.php\r\n&#39;posts_per_page&#39; =&gt; 5, \/\/5\u3092\u4efb\u610f\u306e\u6570\u5b57\u306b\u5909\u66f4\r\n<\/code><\/pre>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u8868\u793a\u9806\u5e8f\u3092\u5909\u66f4<\/h3>\r\n<pre><code class=\"language-php\">\/\/\u8868\u793a\u9806\u5e8f\u3092\u9006\u8ee2\uff08\u524d\u306e\u8a18\u4e8b\u2192\u73fe\u5728\u306e\u8a18\u4e8b\u306e\u9806\u306b\u3059\u308b\uff09\r\n$display_posts = array_reverse($display_posts);\r\n<\/code><\/pre>\r\n\r\n\r\n<h3 class=\"fz-ml\">\u4e26\u3073\u9806\u306e\u5909\u66f4\uff08\u6295\u7a3f\u65e5\u306e\u5834\u5408\uff09<\/h3>\r\n<pre><code class=\"language-php\">$args_date = array(\r\n  &#39;cat&#39; =&gt; $cat_id,\r\n  &#39;posts_per_page&#39; =&gt; 5,\r\n  &#39;orderby&#39; =&gt; &#39;date&#39;,\r\n  &#39;order&#39; =&gt; &#39;DESC&#39;, \/\/ASC\uff08\u53e4\u3044\u9806\uff09\u3092DESC\uff08\u65b0\u3057\u3044\u9806\uff09\u306b\u5909\u66f4\r\n  &#39;post_status&#39; =&gt; &#39;publish&#39;\r\n);\r\n<\/code><\/pre>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u52b9\u679c\u3068\u30e1\u30ea\u30c3\u30c8<\/h2>\r\n<p>\u3053\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u306b\u3088\u308a\u4ee5\u4e0b\u306e\u52b9\u679c\u304c\u671f\u5f85\u3067\u304d\u307e\u3059\uff1a<\/p>\r\n<ol style=\"list-style-type:decimal;\">\r\n  <li><b class=\"fw-600\">\u56de\u904a\u7387\u306e\u5411\u4e0a<\/b>: \u8aad\u8005\u304c\u95a2\u9023\u8a18\u4e8b\u3092\u898b\u3064\u3051\u3084\u3059\u304f\u306a\u308b<\/li>\r\n  <li><b class=\"fw-600\">\u30e6\u30fc\u30b6\u30d3\u30ea\u30c6\u30a3\u306e\u5411\u4e0a<\/b>: \u73fe\u5728\u4f4d\u7f6e\u304c\u660e\u78ba\u3067\u3001\u6b21\u306b\u8aad\u3080\u3079\u304d\u8a18\u4e8b\u304c\u5206\u304b\u308a\u3084\u3059\u3044<\/li>\r\n  <li><b class=\"fw-600\">SEO\u52b9\u679c<\/b>: \u5185\u90e8\u30ea\u30f3\u30af\u306e\u5f37\u5316\u306b\u3088\u308a\u3001\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u8a55\u4fa1\u5411\u4e0a<\/li>\r\n  <li><b class=\"fw-600\">\u96e2\u8131\u7387\u306e\u6539\u5584<\/b>: \u95a2\u9023\u8a18\u4e8b\u3078\u306e\u8a98\u5c0e\u306b\u3088\u308a\u6ede\u5728\u6642\u9593\u306e\u5ef6\u9577<\/li>\r\n  <li><b class=\"fw-600\">\u30b3\u30f3\u30c6\u30f3\u30c4\u306e\u4fa1\u5024\u5411\u4e0a<\/b>: \u8a18\u4e8b\u9593\u306e\u95a2\u9023\u6027\u3092\u660e\u78ba\u306b\u3059\u308b\u3053\u3068\u3067\u3001\u30b5\u30a4\u30c8\u5168\u4f53\u306e\u69cb\u9020\u5316<\/li>\r\n<\/ol>\r\n\r\n\r\n<h2 class=\"fz-xl\">\u307e\u3068\u3081<\/h2>\r\n<p>WordPress\u306e\u6a19\u6e96\u6a5f\u80fd\u3084\u30d7\u30e9\u30b0\u30a4\u30f3\u3067\u306f\u5b9f\u73fe\u3057\u306b\u304f\u3044\u300c\u540c\u4e00\u30ab\u30c6\u30b4\u30ea\u30fc\u5185\u306e\u52b9\u679c\u7684\u306a\u8a18\u4e8b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u300d\u30922\u3064\u306e\u30a2\u30d7\u30ed\u30fc\u30c1\u3067\u5b9f\u88c5\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\r\n<p><b class=\"fw-600\">tocCat.php<\/b>\u306f\u73fe\u5728\u8a18\u4e8b\u3092\u4e2d\u5fc3\u3068\u3057\u305f\u9023\u7d9a\u6027\u3092\u91cd\u8996\u3057\u3001<b class=\"fw-600\">postList.php<\/b>\u306f\u30ab\u30c6\u30b4\u30ea\u30fc\u5168\u4f53\u306e\u6982\u89b3\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u30b5\u30a4\u30c8\u306e\u6027\u8cea\u3084\u76ee\u7684\u306b\u5fdc\u3058\u3066\u6700\u9069\u306a\u65b9\u6cd5\u3092\u9078\u629e\u3057\u3001\u8aad\u8005\u306b\u3068\u3063\u3066\u4fa1\u5024\u306e\u3042\u308b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u4f53\u9a13\u3092\u63d0\u4f9b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\r\n<p>\u4e21\u65b9\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u72ec\u7acb\u3057\u3066\u52d5\u4f5c\u3059\u308b\u305f\u3081\u3001\u540c\u6642\u306b\u4f7f\u7528\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002A\/B\u30c6\u30b9\u30c8\u3092\u884c\u3044\u3001\u3069\u3061\u3089\u304c\u3088\u308a\u52b9\u679c\u7684\u304b\u3092\u691c\u8a3c\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<\/p>\r\n\r\n<hr class=\"rule-hory mt-3r\">\r\n\r\n<p><b class=\"fw-600\">\u6ce8\u610f<\/b>: \u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3059\u308b\u524d\u306f\u3001\u5fc5\u305a\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u3092\u53d6\u3063\u3066\u304b\u3089\u4f5c\u696d\u3092\u884c\u3063\u3066\u304f\u3060\u3055\u3044\u3002\u307e\u305f\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u306b\u3088\u308b\u5f71\u97ff\u3092\u907f\u3051\u308b\u305f\u3081\u3001\u5b50\u30c6\u30fc\u30de\u3067\u306e\u5b9f\u88c5\u3092\u63a8\u5968\u3057\u307e\u3059\u3002<\/p>","protected":false},"excerpt":{"rendered":"WordPress\u306e\u30b5\u30a4\u30c9\u30d0\u30fc\u306b\u73fe\u5728\u8a18\u4e8b\u3092\u542b\u3080\u540c\u4e00\u30ab\u30c6\u30b4\u30ea\u30fc\u306e\u9023\u7d9a\u8a18\u4e8b\u3092\u8868\u793a\u3059\u308b\u30ca\u30d3\u30b2\u30fc\u30b7\u30e7\u30f3\u6a5f\u80fd\u306e\u5b9f\u88c5\u65b9\u6cd5\u3002PHP\u30b3\u30fc\u30c9\u3068CSS\u4ed8\u304d\u3067\u8a73\u3057\u304f\u89e3\u8aac\u3002","protected":false},"author":1,"featured_media":9136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","footnotes":"","vk-ltc-link":"","vk-ltc-target":"0"},"categories":[13],"tags":[],"group":[],"pg":[],"class_list":["post-9125","post","type-post","status-publish","format-standard","has-post-thumbnail","category-wordpress"],"acf":[],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/9125","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=9125"}],"version-history":[{"count":0,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/posts\/9125\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media\/9136"}],"wp:attachment":[{"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/media?parent=9125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/categories?post=9125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/tags?post=9125"},{"taxonomy":"group","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/group?post=9125"},{"taxonomy":"pg","embeddable":true,"href":"https:\/\/code-plus.jp\/gp\/wp-json\/wp\/v2\/pg?post=9125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}