{"id":4476,"date":"2024-02-11T15:02:25","date_gmt":"2024-02-11T06:02:25","guid":{"rendered":"https:\/\/taitan916.info\/blog\/?p=4476"},"modified":"2024-02-25T17:17:21","modified_gmt":"2024-02-25T08:17:21","slug":"post-4476","status":"publish","type":"post","link":"https:\/\/taitan916.info\/blog\/archives\/4476","title":{"rendered":"WordPress\u3067\u30ab\u30c6\u30b4\u30ea\u306b\u512a\u5148\u9806\u4f4d\u3092\u6c7a\u3081\u8907\u6570\u30ab\u30c6\u30b4\u30ea\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u8a18\u4e8b\u306e\u5834\u5408\u306b\u512a\u5148\u9806\u4f4d\u306e\u9ad8\u3044\u30ab\u30c6\u30b4\u30ea\u306e\u8a18\u4e8b\u306e\u307f\u53d6\u5f97"},"content":{"rendered":"<p>WordPress\u3067\u7cbe\u5ea6\u306e\u9ad8\u3044\u95a2\u9023\u8a18\u4e8b\u3092\u8868\u793a\u3055\u305b\u305f\u3044\u3002\u8272\u3005\u8a66\u3057\u305f\u3068\u3053\u308d\u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb\u5074\u3067\u30ab\u30c6\u30b4\u30ea\u306b\u512a\u5148\u9806\u4f4d\u3092\u6c7a\u3081\u3066\u304a\u304d\u3001\u8907\u6570\u30ab\u30c6\u30b4\u30ea\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u8a18\u4e8b\u306e\u5834\u5408\u306f\u512a\u5148\u9806\u4f4d\u306e\u9ad8\u3044\u30ab\u30c6\u30b4\u30ea\u306e\u8a18\u4e8b\u306e\u307f\u53d6\u5f97\u3059\u308b\u3053\u3068\u3067\u5e0c\u671b\u306e\u6319\u52d5\u306b\u306a\u3063\u305f\u3002\u5272\u3068\u529b\u6280\u3067\u30b9\u30de\u30fc\u30c8\u306a\u89e3\u6c7a\u65b9\u6cd5\u3067\u306f\u306a\u3044\u3068\u601d\u3046\u304c\u4e00\u3064\u306e\u624b\u6bb5\u3068\u3057\u3066\u5b9f\u88c5\u65b9\u6cd5\u3092\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u80cc\u666f<\/h2>\n<p>\u5f53\u30b5\u30a4\u30c8\u306e\u5834\u5408\u30011\u3064\u306e\u8a18\u4e8b\u306b\u5bfe\u3057\u3066\u300cCSS \/ jQuery \/ PHP\u300d\u3068\u3044\u3046\u30d0\u30e9\u30d0\u30e9\u306e\u30ab\u30c6\u30b4\u30ea\u3092\u8a2d\u5b9a\u3059\u308b\u30b1\u30fc\u30b9\u304c\u3042\u308b\u3002<\/p>\n<p>\u305d\u306e\u969b\u306b<a href=\"https:\/\/ja.wordpress.org\/plugins\/yet-another-related-posts-plugin\/\" target=\"_blank\" rel=\"noopener\">YARPP<\/a>\u7b49\u306e\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u5c0e\u5165\u3057\u305f\u308a\u3001\u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb\u3067\u30ab\u30c6\u30b4\u30eaID\u3092category__in\u306b\u5165\u308c\u3066\u691c\u7d22\u3057\u305f\u308a\u3057\u3066\u3082\u7d50\u679c\u3068\u3057\u3066\u306f\u5f53\u7136\u3060\u3051\u3069\u300cCSS \/ jQuery \/ PHP\u300d\u30ab\u30c6\u30b4\u30ea\u306e\u8a18\u4e8b\u304c\u8868\u793a\u3055\u308c\u3001\u95a2\u9023\u8a18\u4e8b\u3068\u3057\u3066\u306f\u7cbe\u5ea6\u304c\u4f4e\u3044\u3002<\/p>\n<p>1\u756a\u7cbe\u5ea6\u304c\u9ad8\u3044\u306e\u306f1\u3064\u306e\u8a18\u4e8b\u306b\u5bfe\u3057\u3066\u624b\u52d5\u3067\u95a2\u9023\u8a18\u4e8b\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304f\u3088\u3046\u306a\u65b9\u6cd5\u3060\u3068\u601d\u3046\u304c\u3001\u904e\u53bb\u8a18\u4e8b\u306e\u3053\u3068\u3092\u8003\u3048\u308b\u3068\u3055\u3059\u304c\u306b\u305d\u308c\u306f\u9762\u5012\u3002<\/p>\n<p>\u305d\u306e\u3088\u3046\u306a\u80cc\u666f\u304c\u3042\u308a\u300cWordPress\u3067\u30ab\u30c6\u30b4\u30ea\u306b\u512a\u5148\u9806\u4f4d\u3092\u6c7a\u3081\u8907\u6570\u30ab\u30c6\u30b4\u30ea\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u308b\u8a18\u4e8b\u306e\u5834\u5408\u306b\u512a\u5148\u9806\u4f4d\u306e\u9ad8\u3044\u30ab\u30c6\u30b4\u30ea\u306e\u8a18\u4e8b\u306e\u307f\u53d6\u5f97\u300d\u3068\u3044\u3046\u65b9\u6cd5\u3092\u53d6\u3063\u305f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<h3>\u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb<\/h3>\n<p>\u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb\u306e\u95a2\u9023\u8a18\u4e8b\u8868\u793a\u90e8\u5206\u306b\u4ee5\u4e0b\u3092\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;div id=\"kanren\"&gt;\r\n    &lt;?php\r\n    $categories = get_the_category($post-&gt;ID);\r\n    $category_ID = array();\r\n    foreach($categories as $category):\r\n    array_push( $category_ID, $category -&gt; cat_ID);\r\n    endforeach ;\r\n\r\n    \/\/\u691c\u7d22\u304c\u6709\u52b9\u306a\u30ab\u30c6\u30b4\u30eaID\u30ea\u30b9\u30c8(\u512a\u5148\u9806)\r\n    $kanren_category_list = array(\r\n        80 =&gt; '\u30ab\u30c6\u30b4\u30eaA',\r\n        95 =&gt; '\u30ab\u30c6\u30b4\u30eaB',\r\n        89 =&gt; '\u30ab\u30c6\u30b4\u30eaC',\r\n    );\r\n\r\n    \/\/\u691c\u7d22\u7528\u30ab\u30c6\u30b4\u30eaID\r\n    $search_category_id = 0;\r\n\r\n    \/\/\u30ab\u30c6\u30b4\u30eaID\u30ea\u30b9\u30c8\u3092\u30eb\u30fc\u30d7\u51e6\u7406\u3057\u3001\u6709\u52b9\u306aID\u304c\u3042\u3063\u305f\u5834\u5408\u306f1\u3064\u306e\u307f\u53d6\u5f97\u3057\u3066\u30eb\u30fc\u30d7\u7d42\u4e86\r\n    foreach( (array)$kanren_category_list as $key =&gt; $val ){\r\n        if( in_array($key, $category_ID) ){\r\n            $search_category_id = $key;\r\n            break;\r\n        }\r\n    }\r\n\r\n    \/\/\u30ab\u30c6\u30b4\u30eaID\u3092\u30bb\u30c3\u30c8(\u6709\u52b9\u306a\u30ab\u30c6\u30b4\u30ea\u304c\u7121\u3044\u5834\u5408\u306f0\u304c\u5165\u308a\u95a2\u9023\u8a18\u4e8b\u306f\u8868\u793a\u3055\u308c\u306a\u3044)\r\n    $category_ID = array($search_category_id);\r\n\r\n    $args = array(\r\n       \u00a0'post__not_in' =&gt; array($post -&gt; ID),\r\n       \u00a0'posts_per_page'=&gt; 5,\r\n       \u00a0'category__in' =&gt; $category_ID,\r\n       \u00a0'orderby' =&gt; 'rand',\r\n    );\r\n    $st_query = new WP_Query($args);\r\n    ?&gt;\r\n    &lt;?php if( $st_query -&gt; have_posts() ): ?&gt;\r\n        &lt;h4 class=\"point\"&gt;\r\n            &lt;i class=\"fa fa-th-list\"&gt;&lt;\/i&gt;&amp;nbsp; \u95a2\u9023\u8a18\u4e8b\r\n        &lt;\/h4&gt;\r\n        &lt;?php while ($st_query -&gt; have_posts()) : $st_query -&gt; the_post(); ?&gt;\r\n            &lt;dl class=\"clearfix\"&gt;\r\n                &lt;dt&gt;\r\n                    &lt;a href=\"&lt;?php the_permalink(); ?&gt;\"&gt;\r\n                        &lt;?php if ( has_post_thumbnail() ): \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u6301\u3063\u3066\u3044\u308b\u3068\u304d\u306e\u51e6\u7406 ?&gt;\r\n                            &lt;?php the_post_thumbnail( 'thumb150' ); ?&gt;\r\n                        &lt;?php else: \/\/ \u30b5\u30e0\u30cd\u30a4\u30eb\u3092\u6301\u3063\u3066\u3044\u306a\u3044\u3068\u304d\u306e\u51e6\u7406 ?&gt;\r\n                            &lt;img src=\"&lt;?php echo get_template_directory_uri();?&gt;\/images\/no-img.png\" alt=\"no image\" title=\"no image\" width=\"100\" height=\"100\" \/&gt;\r\n                        &lt;?php endif; ?&gt;\r\n                    &lt;\/a&gt;\r\n                &lt;\/dt&gt;\r\n                &lt;dd&gt;\r\n                    &lt;h5&gt;\r\n                        &lt;a href=\"&lt;?php the_permalink(); ?&gt;\"&gt;\r\n                            &lt;?php the_title(); ?&gt;\r\n                        &lt;\/a&gt;\r\n                    &lt;\/h5&gt;\r\n                &lt;\/dd&gt;\r\n            &lt;\/dl&gt;\r\n        &lt;?php endwhile; ?&gt;\r\n    &lt;?php else: ?&gt;\r\n\r\n    &lt;?php endif; ?&gt;\r\n    &lt;?php wp_reset_postdata(); ?&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>\u300c$kanren_category_list\u300d\u306e\u914d\u5217\u3067key\u3092\u30ab\u30c6\u30b4\u30eaID\u306b\u3001value\u306f\u4f55\u3067\u3082\u3044\u3044\u3051\u3069\u30ab\u30c6\u30b4\u30ea\u540d\u3092\u5165\u308c\u3066\u304a\u304f\u3068\u5206\u304b\u308a\u3084\u3059\u3044\u3002<\/p>\n<h3>(\u5fc5\u8981\u306b\u5fdc\u3058\u3066)\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u306e\u30ab\u30c6\u30b4\u30ea\u30da\u30fc\u30b8\u3067\u30ab\u30c6\u30b4\u30eaID\u3092\u8868\u793a<\/h3>\n<p>WordPress\u30c0\u30c3\u30b7\u30e5\u30dc\u30fc\u30c9\u306e\u30ab\u30c6\u30b4\u30ea\u30da\u30fc\u30b8\u3067\u30ab\u30c6\u30b4\u30eaID\u3092\u8868\u793a\u3059\u308b\u305f\u3081functions.php\u306b\u4ee5\u4e0b\u3092\u8ffd\u8a18\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/\u30d8\u30c3\u30c0\u3068\u30ab\u30e9\u30e0\u306e\u8ffd\u52a0\r\nfunction addCategoryID($columns){\r\n    $columns['id'] = 'ID';\r\n    return $columns;\r\n}\r\nadd_filter('manage_edit-category_columns','addCategoryID');\r\n \r\n\/\/\u9805\u76ee\u306e\u51fa\u529b\r\nfunction addCategoryIDvalue($value, $column_name, $id){\r\n    if($column_name == 'id'){\r\n        echo $id;\r\n    }\r\n}\r\nadd_action('manage_category_custom_column','addCategoryIDvalue',10,3);\r\n \r\n\/\/\u30bd\u30fc\u30c8\u53ef\u80fd\u306b\u3059\u308b\r\nfunction addCategoryIDsort($columns) {\r\n    $columns['id'] = 'ID';\r\n    return $columns;\r\n}\r\nadd_filter( 'manage_edit-category_sortable_columns', 'addCategoryIDsort' );<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u30bf\u30b0\u3082\u8a2d\u5b9a(2024\/02\/21\u8ffd\u8a18)<\/h2>\n<p>\u30bf\u30b0\u3082\u8a2d\u5b9a\u3057\u305f\u65b9\u304c\u3088\u308a\u7cbe\u5ea6\u304c\u4e0a\u304c\u3063\u305f\u3002<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306f\u4ee5\u4e0b\u3067\u8a18\u4e8b\u306b\u7d10\u3065\u304f\u30bf\u30b0\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$tags = get_the_tags($post-&gt;ID);\r\n$tag_ID = array();\r\nforeach( (array)$tags as $tag ):\r\n    if( isset($tag-&gt;term_id) ){\r\n        array_push( $tag_ID, $tag-&gt;term_id);\r\n    }\r\nendforeach;<\/pre>\n<p>\u307e\u305f\u3001\u4ee5\u4e0b\u3067\u30ab\u30c6\u30b4\u30ea\u3082\u691c\u7d22\u5bfe\u8c61\u306b\u542b\u3081\u308b\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">$args = array(\r\n    'post__not_in' =&gt; array($post -&gt; ID),\r\n    'posts_per_page'=&gt; 5,\r\n    'category__in' =&gt; $category_ID,\r\n    'tag__in' =&gt; $tag_ID,\r\n    'orderby' =&gt; 'rand',\r\n);<\/pre>\n<p>&nbsp;<\/p>\n<h2>\u6240\u611f<\/h2>\n<p>\u30ab\u30c6\u30b4\u30ea\u3092\u8ffd\u52a0\u3059\u308b\u5ea6\u306b\u30c6\u30fc\u30de\u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u63db\u3048\u3066\u3044\u304f\u5fc5\u8981\u304c\u3042\u308a\u30b9\u30de\u30fc\u30c8\u306a\u89e3\u6c7a\u65b9\u6cd5\u3068\u306f\u8a00\u3048\u306a\u3044\u3051\u308c\u3069\u3082\u6319\u52d5\u3068\u3057\u3066\u306f\u307e\u3042\u6e80\u8db3\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress\u3067\u7cbe\u5ea6\u306e\u9ad8\u3044\u95a2\u9023\u8a18\u4e8b\u3092\u8868\u793a\u3055\u305b\u305f\u3044\u3002\u8272\u3005\u8a66\u3057\u305f\u3068\u3053\u308d\u30c6\u30fc\u30de\u30d5\u30a1 ... <\/p>\n","protected":false},"author":1,"featured_media":1093,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[24,41],"tags":[],"class_list":["post-4476","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress","category-cms"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/comments?post=4476"}],"version-history":[{"count":5,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4476\/revisions"}],"predecessor-version":[{"id":5018,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/posts\/4476\/revisions\/5018"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media\/1093"}],"wp:attachment":[{"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/media?parent=4476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/categories?post=4476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/taitan916.info\/blog\/wp-json\/wp\/v2\/tags?post=4476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}