{"id":157,"date":"2019-10-18T18:46:41","date_gmt":"2019-10-18T09:46:41","guid":{"rendered":"http:\/\/syrup-factory.com\/memo\/?p=157"},"modified":"2020-01-05T22:44:32","modified_gmt":"2020-01-05T13:44:32","slug":"%e9%96%a2%e9%80%a3%e8%a8%98%e4%ba%8b%e8%a1%a8%e7%a4%ba%e7%94%a8%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%80%8ccontextual-related-posts%e3%80%8d%e3%81%ae%e8%a1%a8%e7%a4%ba%e3%82%92%e3%83%95","status":"publish","type":"post","link":"https:\/\/syrup-factory.com\/memo\/archives\/157","title":{"rendered":"WP \u95a2\u9023\u8a18\u4e8b\u8868\u793a\u7528\u30d7\u30e9\u30b0\u30a4\u30f3\u300cContextual Related Posts\u300d\u306e\u8868\u793a\u3092\u30d5\u30eb\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b"},"content":{"rendered":"<p>wordpress\u306e\u95a2\u9023\u8a18\u4e8b\u8868\u793a\u7528\u30d7\u30e9\u30b0\u30a4\u30f3\u300cContextual Related Posts\u300d\u3002<br \/>\n\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u8a2d\u5b9a\u753b\u9762\u3067\u3001\u3042\u308b\u7a0b\u5ea6\u8868\u793a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3067\u304d\u308b\u304c\u3001\u30d5\u30eb\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308b\u3002<br \/>\n&#8216;crp_custom_template&#8217; \u30d5\u30a3\u30eb\u30bf\u3092\u5229\u7528\u3059\u308c\u3070\u3088\u3044\u3002<\/p>\n<p>\u2193\u3053\u308c\u3092function.php \u306b\u66f8\u304f\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/\u30d6\u30ed\u30b0\u8a18\u4e8b\u306e\u95a2\u9023\u60c5\u5831 \u30ab\u30b9\u30bf\u30e0\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u8a2d\u5b9a(\u30d7\u30e9\u30b0\u30a4\u30f3\u7528)\r\nfunction __crp_custom_template($dmy=null, $posts=[], $args=[]){\r\n\t\/\/$ret = '';\r\n\t$ret = ' ';\t\t\/\/\u25cf\u7a7a\u306e\u5834\u5408\u3001filter\u306e\u5f8c\u3001\u629c\u3051\u305a\u306b\u30d7\u30e9\u30b0\u30a4\u30f3\u306edefault\u306e\u51e6\u7406\u306b\u9032\u3093\u3067\u3057\u307e\u3046\u305f\u3081\u3001\u7a7a\u767d\u3068\u3059\u308b\uff082020.1\uff09\r\n\tif ( $posts ) {\r\n\t\t$i = 0;\r\n\t\tforeach ($posts as $_post) {\r\n\t\t\t$obj = get_post( $_post-&gt;ID );\t\/\/\u8a18\u4e8b\u3092\u53d6\u5f97\u3059\u308b\r\n\t\t\t\/\/\u8272\u3005\u52a0\u5de5\u3059\u308b\r\n\t\t\t$ret .= '&lt;div class=&quot;hogehoge&quot;&gt;' . $obj-&gt;post_title . '&lt;\/div&gt;';\r\n\t\t\t$i++;\r\n\t\t\tif ($i &gt;= 3) {\t\/\/3\u8a18\u4e8b\u3067\u7d42\u308f\u308b\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn $ret;\r\n}\r\nadd_filter( 'crp_custom_template', '__crp_custom_template', 10, 3 );\r\n<\/pre>\n<p>\u30d1\u30e9\u30e1\u30bf\u306e $posts \u306b\u306f\u3001ID\u3068\u65e5\u4ed8\u3060\u3063\u305f\u304b\u3001\u3092\u6301\u3064post\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u5165\u3063\u3066\u3044\u308b\u3002<br \/>\n$args \u306b\u306f\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u8a2d\u5b9a\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u3067\u3001\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u4f7f\u3046\u3053\u3068\u304c\u3067\u304d\u308b\u3002<\/p>\n<p>\u30d5\u30a3\u30eb\u30bf\u306e\u9069\u7528\u7b87\u6240\u306f\u3001\u30d7\u30e9\u30b0\u30a4\u30f3\u306e\u30bd\u30fc\u30b9\u306e\u4ee5\u4e0b\u306b\u3042\u308b\u3002<br \/>\n\/contextual-related-posts\/includes\/main-query.php<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfunction get_crp( $args = array() ) {\r\n\t\uff1a\r\n\t$custom_template = apply_filters( 'crp_custom_template', null, $results, $args );\r\n<\/pre>\n<p>\u25cf2020.1 \u8ffd\u8a18<br \/>\n\u8a72\u5f53\u8a18\u4e8b\u304c\u30bc\u30ed\u306e\u6642\u3001\u7a7a\u767d\u3092\u8fd4\u3059\u3088\u3046\u306b\u3057\u305f\u3002filter\u306e\u5f8c\u3001\u305d\u3053\u3067\u629c\u3051\u305a\u306b\u30d7\u30e9\u30b0\u30a4\u30f3\u306edefault\u306e\u51e6\u7406\u306b\u9032\u3093\u3067\u3057\u307e\u3046\u305f\u3081\u3002\uff08\u305d\u3057\u3066\u30d7\u30e9\u30b0\u30a4\u30f3\u5074\u3067\u30a8\u30e9\u30fc\u304c\u51fa\u308b\uff09<br \/>\n\u7a7a\u767d\u304c\u51fa\u529b\u3055\u308c\u3066\u56f0\u308b\u5834\u5408\u306f\u3001trim\u5f8c\u306e\u6587\u5b57\u9577\u3067\u7a7a\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u3001\u7a7a\u3067\u306a\u3044\u5834\u5408\u306e\u307f\u51fa\u529b\u3059\u308b\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nif ( function_exists( 'echo_crp' ) ) { \r\n\t$ret = get_crp(['echo'=&gt;false]);\r\n\tif (strlen(trim($ret)) &gt; 0) {\r\n\t\techo $ret;\r\n\t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>wordpress\u306e\u95a2\u9023\u8a18\u4e8b\u8868\u793a\u7528\u30d7\u30e9\u30b0\u30a4\u30f3\u300cContextual Related Posts\u300d\u3002  &#8230;<\/p>\n<p> <a class=\"continue-reading-link\" href=\"https:\/\/syrup-factory.com\/memo\/archives\/157\"><span>Continue reading<\/span><i class=\"crycon-right-dir\"><\/i><\/a> <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/posts\/157"}],"collection":[{"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/comments?post=157"}],"version-history":[{"count":6,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/posts\/157\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/media?parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/categories?post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/syrup-factory.com\/memo\/wp-json\/wp\/v2\/tags?post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}