{"id":6819,"date":"2022-07-21T18:00:28","date_gmt":"2022-07-21T09:00:28","guid":{"rendered":"https:\/\/www.sria.co.jp\/blog\/?p=6819"},"modified":"2022-07-21T16:53:56","modified_gmt":"2022-07-21T07:53:56","slug":"6819","status":"publish","type":"post","link":"https:\/\/www.sria.co.jp\/blog\/2022\/07\/6819\/","title":{"rendered":"\u3010WordPress\u3011Advanced Custom Fields\u306eTable\u306bcolspan\u3092\u9069\u7528\u3057\u3066\u307f\u308b"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002<br \/>\n\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u8fbb\u3067\u3059\u3002<\/p>\n<p>\u304a\u4ed5\u4e8b\u306e\u4e2d\u3067\u3001Advanced Custom Fields\u306eTable\u3092\u5229\u7528\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308a\u307e\u3057\u305f\u3002<br \/>\n\u305d\u306e\u6642\u306b\u300c<strong>\u5185\u5bb9\u304c\u540c\u3058\u30bb\u30eb\u540c\u58eb\u3092colspan\u3067\u7e4b\u3050<\/strong>\u300d\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u305d\u306e\u5099\u5fd8\u9332\u3067\u3059\u3002<\/p>\n<h3>\u307e\u305a\u306f\u30b7\u30f3\u30d7\u30eb\u306bAdvanced Custom Fields \u306eTable\u3092\u51fa\u529b\u3057\u3066\u307f\u308b<\/h3>\n<p>Advanced Custom Fields\u3092\u5229\u7528\u3057\u3066\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u306e\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u7528\u610f\u3057\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17.png\"><img loading=\"lazy\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17.png\" alt=\"\" width=\"1486\" height=\"424\" class=\"aligncenter size-full wp-image-6826\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17.png 1486w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17-300x86.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17-1024x292.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/60d63e4efa4a1a31f6fe6490a4304b17-768x219.png 768w\" sizes=\"(max-width: 1486px) 100vw, 1486px\" \/><\/a><\/p>\n<p>\u305d\u3057\u3066\u3001\u4e0a\u8a18\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u51fa\u529b\u3059\u308b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre>\n<?php\n$table = get_field($table_name); \/\/ \u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u53d6\u5f97\nif (!empty($table)) :  \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u4e2d\u8eab\u304c\u3042\u308c\u3070\u51fa\u529b\n?>\n  <table>\n    <?php\n    if (!empty($table['header'])) : \/\/ thead\u51fa\u529b\n    ?>\n      <thead>\n        <tr>\n          <?php foreach ($table['header'] as $th) : ?>\n            <th>\n              <?php echo $th['c']; ?>\n            <\/th>\n          <?php endforeach; ?>\n        <\/tr>\n      <\/thead>\n    <?php endif; ?>\n    <tbody>\n      <?php\n      foreach ($table['body'] as $tr) : \/\/ \u30c6\u30fc\u30d6\u30eb\u306e\u4e2d\u8eab\u3092\u51fa\u529b\n      ?>\n        <tr>\n          <?php foreach ($tr as $td) : ?>\n            <td>\n              <?php echo $td['c']; ?>\n            <\/td>\n          <?php endforeach; ?>\n        <\/tr>\n      <?php endforeach; ?>\n    <\/tbody>\n  <\/table>\n<?php endif; ?>\n<\/pre>\n<p>\u5b9f\u969b\u306b\u51fa\u529b\u3059\u308b\u3068\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3.png\"><img loading=\"lazy\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3.png\" alt=\"\" width=\"1470\" height=\"304\" class=\"aligncenter size-full wp-image-6828\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3.png 1470w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3-300x62.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3-1024x212.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/edef9f15fb44309fd9ec7588749e1ec3-768x159.png 768w\" sizes=\"(max-width: 1470px) 100vw, 1470px\" \/><\/a><\/p>\n<p>\u3046\u307e\u3044\u5177\u5408\u306b\u30ab\u30b9\u30bf\u30e0\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u8868\u793a\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u3053\u3053\u307e\u3067\u306f\u7279\u306b\u554f\u984c\u306a\u3044\u306e\u3067\u3059\u304c\u3001\u540c\u3058\u5185\u5bb9\u306e\u30bb\u30eb\u304c\u9023\u7d9a\u3057\u3066\u51fa\u529b\u3055\u308c\u308b\u306e\u306f\u3001\u3069\u3046\u3082\u5197\u9577\u7684\u3067\u3059\u3088\u306d\u3002<br \/>\n\u2026\u3068\u3044\u3046\u308f\u3051\u3067\u3001<strong>\u96a3\u5408\u3046\u30bb\u30eb\u306e\u5185\u5bb9\u304c\u540c\u3058\u5834\u5408\u306f\u3001colspan\u3067\u9023\u7d50\u3057\u305f\u4e0a\u3067\u8868\u793a\u3059\u308b<\/strong>\u3088\u3046\u6539\u4fee\u3092\u52a0\u3048\u3066\u307f\u307e\u3059\u3002<\/p>\n<h3>\u96a3\u308a\u5408\u3046\u30bb\u30eb\u306e\u5185\u5bb9\u304c\u540c\u3058\u5834\u5408\u306b\u3001colspan\u3067\u307e\u3068\u3081\u308b\u51e6\u7406<\/h3>\n<p>\u65e9\u901f\u3067\u3059\u304c\u3001\u6539\u4fee\u3057\u305f\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre>\n<?php\n$table = get_field($table_name);\nif (!empty($table)) : ?>\n  <table>\n    <?php if (!empty($table['header'])) : ?>\n      <thead>\n        <tr>\n          <?php\n          $flat_th = array();\n\n          foreach ($table['header'] as $th) :\n            if (count($flat_th) === 0) {\n              array_push($flat_th, array(\"count\" => 1, \"text\" => $th['c']));\n              continue;\n            }\n\n            if ($th['c'] === $flat_th[count($flat_th) - 1][\"text\"]) {\n              $flat_th[count($flat_th) - 1][\"count\"] += 1;\n            } else {\n              array_push($flat_th, array(\"count\" => 1, \"text\" => $th['c']));\n            }\n          endforeach; ?>\n\n          <?php foreach ($flat_th as $th) : ?>\n            <?php if ($th['count'] > 1) : ?>\n              <th colspan=\"<?php echo $th['count']; ?>\">\n                <?php echo $th['text']; ?>\n              <\/th>\n            <?php else : ?>\n              <th>\n                <?php echo $th['text']; ?>\n              <\/th>\n            <?php endif; ?>\n          <?php endforeach; ?>\n        <\/tr>\n      <\/thead>\n    <?php endif; ?>\n    <tbody>\n      <?php foreach ($table['body'] as $tr) : ?>\n        <tr>\n          <?php\n          $flat_td = array();\n\n          foreach ($tr as $td) :\n            if (count($flat_td) === 0) {\n              array_push($flat_td, array(\"count\" => 1, \"text\" => $td['c']));\n              continue;\n            }\n\n            if ($td['c'] === $flat_td[count($flat_td) - 1][\"text\"]) {\n              $flat_td[count($flat_td) - 1][\"count\"] += 1;\n            } else {\n              array_push($flat_td, array(\"count\" => 1, \"text\" => $td['c']));\n            }\n          endforeach;\n          ?>\n\n          <?php foreach ($flat_td as $td) : ?>\n            <?php if ($td['count'] > 1) : ?>\n              <td colspan=\"<?php echo $td['count']; ?>\">\n                <?php echo $td['text']; ?>\n              <\/td>\n            <?php else : ?>\n              <td>\n                <?php echo $td['text']; ?>\n              <\/td>\n            <?php endif; ?>\n          <?php endforeach; ?>\n        <\/tr>\n      <?php endforeach; ?>\n    <\/tbody>\n  <\/table>\n<?php endif; ?>\n<\/pre>\n<p>\u753b\u9762\u4e0a\u306e\u8868\u793a\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10.png\"><img loading=\"lazy\" src=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10.png\" alt=\"\" width=\"1464\" height=\"300\" class=\"aligncenter size-full wp-image-6859\" srcset=\"https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10.png 1464w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10-300x61.png 300w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10-1024x210.png 1024w, https:\/\/www.sria.co.jp\/blog\/wp-content\/uploads\/2022\/07\/fab9dec5707571a5c4ef9aa7738dff10-768x157.png 768w\" sizes=\"(max-width: 1464px) 100vw, 1464px\" \/><\/a><\/p>\n<p>\u5b9f\u88c5\u3057\u305f\u51e6\u7406\u306f\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u3059\u3002\u3056\u3063\u304f\u308a\u3068\u3057\u305f\u6d41\u308c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3002<\/p>\n<ol>\n<li>\u7a7a\u914d\u5217\uff08$flat_td\/$flat_th\uff09\u3092\u7528\u610f\u3059\u308b<\/li>\n<li>\u306f\u3058\u3081\u306b\u30c6\u30fc\u30d6\u30eb\u306e\u5185\u5bb9\u3092foreach\u6587\u3067\u7cbe\u67fb\u3059\u308b<\/li>\n<li>\u96a3\u308a\u5408\u3046\u30bb\u30eb\u306e\u5185\u5bb9\u304c\u9055\u3046\u306a\u3089\u3001\u65b0\u3057\u3044\u8981\u7d20\u3068\u3057\u3066$flat_td\uff08$flat_th\uff09\u3078\u8ffd\u52a0\u3059\u308b<\/li>\n<li>\u96a3\u308a\u5408\u3046\u30bb\u30eb\u306e\u5185\u5bb9\u304c\u540c\u3058\u306a\u3089\u3001\u51fa\u73fe\u56de\u6570\uff08$flat_td[index\u756a\u76ee][count]\uff09\u30921\u5897\u3084\u3059<\/li>\n<li>$flat_td\uff08$flat_th\uff09\u3092\u5143\u306b\u3001HTML\u3092\u51fa\u529b\u3059\u308b<\/li>\n<li>$flat_td\uff08$flat_th\uff09\u306e\u51fa\u529b\u6642\u306b\u3001count\u304c1\u3088\u308a\u5927\u304d\u3051\u308c\u3070\u3001td\/th\u30bf\u30b0\u306bcolspan=&#8221;count\u306e\u5024&#8221;\u3092\u4ed8\u4e0e\u3059\u308b<\/li>\n<li>$flat_td\uff08$flat_th\uff09\u306e\u51fa\u529b\u6642\u306b\u3001count\u304c1\u3067\u3042\u308c\u3070\u3001\u7279\u306b\u4f55\u3082\u305b\u305a\u3001td\/th\u30bf\u30b0\u306b\u4e2d\u8eab\u3092\u5165\u308c\u3066\u51fa\u529b\u3059\u308b<\/li>\n<\/ol>\n<p>\u8981\u306f\u2026\u3001<br \/>\n\u30c6\u30fc\u30d6\u30eb\u3092\u51fa\u529b\u3059\u308b\u524d\u306b\u3001\u4e00\u5ea6\u30c6\u30fc\u30d6\u30eb\u306e\u5168\u9805\u76ee\u3092\u7cbe\u67fb\u3059\u308b<br \/>\n\u2192 \u540c\u3058\u5185\u5bb9\u306e\u30bb\u30eb\u304c\u3042\u308c\u3070\u3001\u305d\u306e\u30bb\u30eb\u304c\u4f55\u56de\u51fa\u73fe\u3059\u308b\u304b\u3092\u4fdd\u6301\u3059\u308b<br \/>\n\u2192 \u3042\u3068\u306f\u51fa\u73fe\u3059\u308b\u56de\u6570\u3092colspan\u306b\u5165\u308c\u3066\u3001\u51fa\u529b\u3059\u308b<br \/>\n\u2026\u3063\u3066\u3060\u3051\u3067\u3059\u306d\u3002<\/p>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>\u4eca\u56de\u306f\u3001Advanced Custom Fields \u306eTable\u3092\u51fa\u529b\u3059\u308b\u6642\u306bcolspan\u3092\u9069\u7528\u3059\u308b\u3061\u3087\u3063\u3068\u3057\u305f\u30c6\u30af\u30cb\u30c3\u30af\u306e\u3054\u7d39\u4ecb\u3067\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3001\u307e\u305f\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u3002 \u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u8fbb\u3067\u3059\u3002 \u304a\u4ed5\u4e8b\u306e\u4e2d\u3067\u3001Advanced Custom Fields\u306eTable\u3092\u5229\u7528\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308a\u307e\u3057\u305f\u3002 \u305d\u306e\u6642\u306b\u300c\u5185\u5bb9\u304c\u540c\u3058\u30bb\u30eb\u540c\u58eb\u3092colspan\u3067\u7e4b\u3050\u300d\u51e6\u7406\u3092\u5b9f\u88c5\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u305d\u306e\u5099\u5fd8&#8230;<\/p>\n","protected":false},"author":5,"featured_media":6820,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[50,78],"_links":{"self":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/6819"}],"collection":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/comments?post=6819"}],"version-history":[{"count":39,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/6819\/revisions"}],"predecessor-version":[{"id":6863,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/posts\/6819\/revisions\/6863"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media\/6820"}],"wp:attachment":[{"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/media?parent=6819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/categories?post=6819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sria.co.jp\/blog\/wp-json\/wp\/v2\/tags?post=6819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}