{"id":493,"date":"2017-03-07T18:00:36","date_gmt":"2017-03-07T09:00:36","guid":{"rendered":"https:\/\/fastcoding.jp\/blog\/?p=493"},"modified":"2024-11-01T20:15:54","modified_gmt":"2024-11-01T11:15:54","slug":"wordpress-random","status":"publish","type":"post","link":"https:\/\/fastcoding.jp\/blog\/all\/system\/wordpress-random\/","title":{"rendered":"\u3010WordPress\u3011\u8a18\u4e8b\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u8868\u793a\u3055\u305b\u308b\u65b9\u6cd5\uff01\u30d7\u30e9\u30b0\u30a4\u30f3\u4e0d\u8981\uff01"},"content":{"rendered":"<div class=\"the_content\"><p><img decoding=\"async\" class=\"the_post_thumbnail\" src=\"https:\/\/fastcoding.jp\/blog\/wp-content\/uploads\/2017\/03\/rendom_keyimg3.png\" alt=\"\u3010WordPress\u3011\u8a18\u4e8b\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u8868\u793a\u3055\u305b\u308b\u65b9\u6cd5\uff01\u30d7\u30e9\u30b0\u30a4\u30f3\u4e0d\u8981\uff01\"><\/p>\n<p>FASTCODING-Vietnam\u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u3001\u30b8\u30a2\u30f3\u3067\u3059\u3002<\/p>\n<p>Web\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3044\u3066\u300c\u30e9\u30f3\u30c0\u30e0\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080\u300d\u30da\u30fc\u30b8\u3092\u898b\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304b\uff1f<\/p>\n<p>\u5177\u4f53\u7684\u306b\u306fWeb\u30b5\u30a4\u30c8\u3092\u8868\u793a\u3059\u308b\u3068<br \/>\n\u6700\u521d\u306f\u308a\u3093\u3054\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u304c1\u756a\u4e0a\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u305f\u306e\u306b<br \/>\n\u540c\u3058\u30da\u30fc\u30b8\u3092\u66f4\u65b0\u3057\u3066\u307f\u305f\u3089\u3001\u6b21\u306f\u307f\u304b\u3093\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u304c1\u756a\u4e0a\u306b\u6765\u3066\u3044\u308b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/fastcoding.jp\/blog\/wp-content\/uploads\/2017\/03\/rendom_01.png\" alt=\"Web\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3044\u3066\u300c\u30e9\u30f3\u30c0\u30e0\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080\u300d\u30da\u30fc\u30b8\u3092\u898b\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304b\uff1f\"><\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u30da\u30fc\u30b8\u3092\u518d\u8aad\u307f\u8fbc\u307f\u3057\u305f\u3089\u3001\u6bce\u56de\u9055\u3046\u8a18\u4e8b\u304c\u8868\u793a\u3055\u308c\u308b\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><!--\n\n<p class=\"text_box_yellow\">[ Demo ]\u30da\u30fc\u30b8\u306f\u3053\u3061\u3089<\/p>\n\n--><\/p>\n<p>\u3053\u306e\u6a5f\u80fd\u306f\u6295\u7a3f\u6570\u304c\u591a\u3044\u30d6\u30ed\u30b0\u306a\u3069\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u30da\u30fc\u30b8\u3092\u66f4\u65b0\u3059\u308b\u3068\u6bce\u56de\u30e9\u30f3\u30c0\u30e0\u306b\u9055\u3046\u8a18\u4e8b\u304c\u8868\u793a\u3055\u308c\u308b\u306e\u3067<br \/>\n\u8a18\u4e8b\u306b\u5bfe\u3057\u3066\u306e\u8aad\u307f\u30e0\u30e9\u304c\u5c11\u306a\u304f\u306a\u308a\u3001<br \/>\n\u307e\u3093\u3079\u3093\u306a\u304f\u8272\u3005\u306a\u8a18\u4e8b\u3092\u30e6\u30fc\u30b6\u306b\u8aad\u3093\u3067\u3082\u3089\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fWordPress\u3067\u3053\u306e\u6a5f\u80fd\u3092\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<hr>\n<h2>WordPress\u3067\u8a18\u4e8b\u3092\u30e9\u30f3\u30c0\u30e0\u306b\u8868\u793a\u3055\u305b\u308b\u65b9\u6cd5<\/h2>\n<p>\u307e\u305a\u30ab\u30b9\u30bf\u30e0\u30da\u30fc\u30b8\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u306e2\u30d1\u30bf\u30fc\u30f3\u4f5c\u6210\u3057\u305f\u306e\u3067\u3001\u304a\u597d\u304d\u306a\u307b\u3046\u3092\u4f7f\u7528\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p class=\"text_box_red\">\n#1 : WordPress\u30c6\u30fc\u30de\u5185\u306b\u76f4\u63a5\u8a18\u8ff0\u3059\u308b\u5834\u5408<br \/>\n#2 : \u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\u3068\u3057\u3066\u4f7f\u3046\u5834\u5408\n<\/p>\n<hr>\n<h3>#1 : WordPress\u30c6\u30fc\u30de\u5185\u306b\u76f4\u63a5\u8a18\u8ff0\u3059\u308b\u5834\u5408<\/h3>\n<p>[\u2193] \u8a18\u4e8b\u3092\u8868\u793a\u3055\u305b\u305f\u3044php\u30d5\u30a1\u30a4\u30eb :<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php query_posts(array(&#039;orderby&#039; =&gt; &#039;rand&#039;, &#039;showposts&#039; =&gt; 5));\r\nif (have_posts()) :\r\nwhile (have_posts()) : the_post(); ?&gt;\r\n\/* \u7e70\u308a\u8fd4\u3057\u8868\u793a\u3055\u305b\u308b\u90e8\u5206 *\/\r\n&lt;h1&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h1&gt;\r\n&lt;?php the_content(); ?&gt;\r\n&lt;?php endwhile; endif; ?&gt;\r\n<\/pre>\n<p>\u300c&#8217;orderby&#8217; => &#8216;rand&#8217;\u300d\u3067\u8a18\u4e8b\u306e\u30e9\u30f3\u30c0\u30e0\u8868\u793a\u3092\u8a2d\u5b9a\u3057\u3001<br \/>\n\u300c&#8217;showposts&#8217; => 5\u300d\u3067\u8a18\u4e8b\u306e\u8868\u793a\u4ef6\u6570\u3092\u5236\u5fa1\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<hr>\n<h3>#2 : \u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\u3068\u3057\u3066\u4f7f\u3046\u5834\u5408<\/h3>\n<p>WordPress\u306e\u8a18\u4e8b\u306e\u30e9\u30f3\u30c0\u30e0\u8868\u793a\u306f\u7c21\u5358\u306aWP_Query\u306e\u30eb\u30fc\u30d7\u3067\u3059\u3002<\/p>\n<p>\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\u306elimit\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u306b\u300c5\u300d\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u304c\u3001<br \/>\n\u3053\u308c\u306f\u30e9\u30f3\u30c0\u30e0\u8a18\u4e8b\u30925\u3064\u3060\u3051\u3092\u8868\u793a\u3059\u308b\u3068\u3044\u3046\u610f\u5473\u3067\u3059\u3002<br \/>\n\u3053\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u8a18\u4e8b\u306e\u8868\u793a\u4ef6\u6570\u3092\u5909\u66f4\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>[\u2193] \u56fa\u5b9a\u30da\u30fc\u30b8\u5185\u3067\u4f7f\u7528\u3059\u308b\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9 :<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">&#x5B;random_posts limit=5]<\/pre>\n<p>[\u2193] functions.php :<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php \r\nfunction random_posts($attrs = array()){\r\n\tob_start();\r\n\t$limit = !empty($attrs&#x5B;&#039;limit&#039;]) ? $attrs&#x5B;&#039;limit&#039;] : 0;\r\n\t?&gt;\r\n\t&lt;?php\r\n\t\r\n\t$args = array(\r\n\t\t&#039;post_type&#039; =&gt; &#039;post&#039;,\r\n\t\t&#039;post_status&#039; =&gt; &#039;publish&#039;,\r\n\t\t&#039;orderby&#039;\t=&gt; &#039;rand&#039;, \/\/ \u8a18\u4e8b\u306e\u30e9\u30f3\u30c0\u30e0\u8868\u793a\u8a2d\u5b9a\r\n\t\t&#039;posts_per_page&#039;\t=&gt; $limit,\r\n\t\t);\r\n\r\n\t$posts_query = new WP_Query( $args ); \r\n\t\r\n\tif ($posts_query-&gt;have_posts()) :\r\n\twhile ($posts_query-&gt;have_posts()) : $posts_query-&gt;the_post(); ?&gt;\r\n\t\/* \u7e70\u308a\u8fd4\u3057\u8868\u793a\u3055\u305b\u308b\u90e8\u5206 *\/\r\n\t&lt;div class=&quot;post-item&quot;&gt;\r\n\t\t&lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;\/a&gt;&lt;\/h2&gt;\r\n\t\t&lt;?php echo get_the_excerpt(); ?&gt;\r\n\t&lt;\/div&gt; \r\n\t&lt;?php endwhile;\r\n\tendif; ?&gt;\r\n\t&lt;?php \r\n\treturn ob_get_clean();\r\n}\r\nadd_shortcode(&#039;random_posts&#039;,&#039;random_posts&#039;);\r\n?&gt;\r\n<\/pre>\n<p>\u300c\u7e70\u308a\u8fd4\u3057\u8868\u793a\u3055\u305b\u308b\u90e8\u5206\u300d\u306e\u4e2d\u306b\u306f\u30bf\u30a4\u30c8\u30eb\u3068\u672c\u6587\u3060\u3051\u5165\u308c\u3066\u3042\u308a\u307e\u3059\u304c<br \/>\nHTML\u3092\u7de8\u96c6\u3059\u308c\u3070\u3001\u4efb\u610f\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u7e70\u308a\u8fd4\u3057\u8868\u793a\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<hr>\n<p>\u3044\u304b\u304c\u3067\u3057\u305f\u304b\uff1f<\/p>\n<p>WordPress\u69cb\u7bc9\u6848\u4ef6\u3067\u304a\u56f0\u308a\u3067\u3057\u305f\u3089FASTPRESS\u307e\u3067\u304a\u6c17\u8efd\u306b\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a class=\"trans\" href=\"https:\/\/fastcoding.jp\/wordpress\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/fastcoding.jp\/blog\/wp-content\/uploads\/2017\/03\/btn_fastspress.png\" alt=\"\u4fa1\u683c\u3067\u9ad8\u54c1\u8cea\u306eWordPress\u5236\u4f5c\u306fFASTPRESS(\u30d5\u30a1\u30b9\u30c8\u30d7\u30ec\u30b9)\"><\/a><\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>FASTCODING-Vietnam\u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u30a8\u30f3\u30b8\u30cb\u30a2\u3001\u30b8\u30a2\u30f3\u3067\u3059\u3002 Web\u30b5\u30a4\u30c8\u3092\u898b\u3066\u3044\u3066\u300c\u30e9\u30f3\u30c0\u30e0\u306b\u8a18\u4e8b\u3092\u8aad\u307f\u8fbc\u3080\u300d\u30da\u30fc\u30b8\u3092\u898b\u305f\u3053\u3068\u306f\u3042\u308a\u307e\u3059\u304b\uff1f \u5177\u4f53\u7684\u306b\u306fWeb\u30b5\u30a4\u30c8\u3092\u8868\u793a\u3059\u308b\u3068 \u6700\u521d\u306f\u308a\u3093\u3054\u306b\u95a2\u3059\u308b\u8a18\u4e8b\u304c [&hellip;]<\/p>\n","protected":false},"author":14,"featured_media":872,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[15,30],"tags":[34,26],"class_list":["post-493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system","category-wordpress","tag-php","tag-wordpress"],"acf":[],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/fastcoding.jp\/blog\/wp-content\/uploads\/2017\/03\/rendom_keyimg3.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/posts\/493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/comments?post=493"}],"version-history":[{"count":28,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/posts\/493\/revisions"}],"predecessor-version":[{"id":7865,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/posts\/493\/revisions\/7865"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/media\/872"}],"wp:attachment":[{"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/media?parent=493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/categories?post=493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastcoding.jp\/blog\/wp-json\/wp\/v2\/tags?post=493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}