{"id":168314,"date":"2013-11-01T00:52:29","date_gmt":"2013-10-31T15:52:29","guid":{"rendered":""},"modified":"2016-07-30T20:33:37","modified_gmt":"2016-07-30T20:33:37","slug":"single%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e3%81%ae%e6%97%a5%e6%99%82%e6%8c%87%e5%ae%9asql%e3%81%ae%e7%99%ba%e8%a1%8c%ef%bc%88ajax%e3%83%ad%e3%83%bc%e3%83%87%e3%82%a3%e3%83%b3%e3%82%b0%e3%83%bbjavascr","status":"closed","type":"topic","link":"https:\/\/ja.wordpress.org\/support\/topic\/single%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%a7%e3%81%ae%e6%97%a5%e6%99%82%e6%8c%87%e5%ae%9asql%e3%81%ae%e7%99%ba%e8%a1%8c%ef%bc%88ajax%e3%83%ad%e3%83%bc%e3%83%87%e3%82%a3%e3%83%b3%e3%82%b0%e3%83%bbjavascr\/","title":{"rendered":"single\u30da\u30fc\u30b8\u3067\u306e\u65e5\u6642\u6307\u5b9aSQL\u306e\u767a\u884c\uff08Ajax\u30ed\u30fc\u30c7\u30a3\u30f3\u30b0\u30fbJavascript\u95a2\u4fc2\uff09"},"content":{"rendered":"<p>\u53c2\u8003\u30b5\u30a4\u30c8\uff1aWordPress \u30da\u30fc\u30b8\u30f3\u30b0\u306f\u3084\u3081\u3066Ajax\u30ed\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3059\u308b\uff08http:\/\/hijiriworld.com\/web\/wp-ajax-loading\/\uff09<\/p>\n<p><strong>\u3084\u308a\u305f\u3044\u4e8b<\/strong><br \/>\n\uff11\uff0esingle\u30da\u30fc\u30b8\u306b\u3066\u30d0\u30c3\u30af\u30ca\u30f3\u30d0\u30fc\uff08\u8868\u793a\u4e2d\u306e\u8a18\u4e8b\u3088\u308a\u904e\u53bb\u306e\u6295\u7a3f\u306e\u307f\uff09\u306e\u4e00\u89a7\u8868\u793a<br \/>\n\uff12\uff0e\u4e00\u89a7\u306e\u8aad\u307f\u8fbc\u307f\u30925\u4ef6\u305a\u3064Ajax\u30ed\u30fc\u30c7\u30a3\u30f3\u30b0\u3067\u975e\u540c\u671f\u306b\u3057\u305f\u3044<\/p>\n<p><strong>\u3046\u307e\u304f\u3044\u304b\u306a\u3044\u4e8b<\/strong><br \/>\nSQL\u767a\u884c\u306e\u969b\u306b\u3001post_date\u304c\u3046\u307e\u304f\u53d6\u5f97\u30fb\u6bd4\u8f03\u3067\u304d\u306a\u3044<\/p>\n<p><strong>\u30b3\u30fc\u30c9<\/strong><br \/>\n\u307b\u307c\u53c2\u8003\u30b5\u30a4\u30c8\u306e\u307e\u307e\u3067\u3059\u304c\u3001header.php\u3001single.php\u3001more-disp.php\u306e3\u30d5\u30a1\u30a4\u30eb\u306b\u307e\u305f\u304c\u3063\u3066\u3044\u307e\u3059<\/p>\n<p>\u3010header.php\u3011\uff08jQuery\u8aad\u307f\u8fbc\u307f\u3068Javascript\uff09<\/p>\n<pre><code>&lt;script type=&quot;text\/javascript&quot;&gt;\nvar now_post_num = 5; \/\/ \u73fe\u5728\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u6570\nvar get_post_num = 5; \/\/ \u4e00\u5ea6\u306b\u53d6\u5f97\u3059\u308b\u6570\n\n$(function() {\n    $(&quot;#more_disp a&quot;).live(&quot;click&quot;, function() {\n\n        $(&quot;#more_disp&quot;).html(&#039;&lt;img class=&quot;ajax_loading&quot; src=&quot;\u753b\u50cfURL&quot; \/&gt;&#039;);\n\n        $.ajax({\n            type: &#039;post&#039;,\n            url: &#039;more-disp.php\u307e\u3067\u306eURL&#039;,\n            data: {\n                &#039;now_post_num&#039;: now_post_num,\n                &#039;get_post_num&#039;: get_post_num\n            },\n            success: function(data) {\n                now_post_num = now_post_num + get_post_num;\n                $(&quot;#single-list&quot;).append(data);\n                $(&quot;#more_disp&quot;).remove();\n                $(&quot;#single-list&quot;).append(&#039;&lt;div id=&quot;more_disp&quot;&gt;&lt;a href=&quot;#&quot;&gt;\u3082\u3063\u3068\u8868\u793a&lt;\/a&gt;&lt;\/div&gt;&#039;);\n            }\n        });\n        return false;\n    });\n});\n&lt;\/script&gt;<\/code><\/pre>\n<p>\u3010single.php\u3011\uff08\u30c7\u30d5\u30a9\u306e5\u4ef6\u3092\u8868\u793a\uff09<\/p>\n<pre><code>&lt;section id=&quot;single-list&quot;&gt;\n&lt;?php\nfunction my_posts_where( $where = &#039;&#039; ) {\n  global $post;\n  $where .= &quot; AND post_date &lt; &#039;&quot;\n         . $post-&gt;post_date . &quot;&#039;&quot;;\n  return $where;\n}\nadd_filter( &#039;posts_where&#039;, &#039;my_posts_where&#039; );\n\/\/ \u8868\u793a\u4e2d\u306e\u8a18\u4e8b\u3088\u308a\u53e4\u3044\u3082\u306e\u9650\u5b9a\n\n$posts = get_posts( array(\n  &#039;posts_per_page&#039; =&gt; 5,  \/\/ \u8868\u793a\u4ef6\u6570\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\n  &#039;suppress_filters&#039; =&gt; false,\n) );\nremove_filter( &#039;posts_where&#039;, &#039;my_posts_where&#039; );\nforeach ( $posts as $post ) {\n  setup_postdata( $post );\n?&gt;\n            &lt;article&gt;\n                &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;\n            &lt;\/article&gt;\n&lt;?php\n}\nwp_reset_postdata();\n?&gt;\n    &lt;div id=&quot;more_disp&quot;&gt;&lt;a href=&quot;#&quot;&gt;\u3082\u3063\u3068\u8868\u793a&lt;\/a&gt;&lt;\/div&gt;\n&lt;\/section&gt;<\/code><\/pre>\n<p>\u3010more-disp.php\u3011\uff08SQL\u306e\u767a\u884c\uff09<\/p>\n<pre><code>&lt;?php\nrequire_once(&quot;..\/..\/..\/wp-config.php&quot;);\n\n$now_post_num = $_POST[&#039;now_post_num&#039;];\n$get_post_num = $_POST[&#039;get_post_num&#039;];\n$sql = &quot;SELECT\n        $wpdb-&gt;posts.ID,\n        $wpdb-&gt;posts.post_title,\n        $wpdb-&gt;posts.post_excerpt\n    FROM\n        $wpdb-&gt;posts\n    WHERE\n        $wpdb-&gt;posts.post_type = &#039;post&#039; AND $wpdb-&gt;posts.post_status = &#039;publish&#039;\n        $wpdb-&gt;posts.post_date DESC\n    LIMIT $now_post_num, $get_post_num&quot;;\n\n$results = $wpdb-&gt;get_results($sql);\n$html = &quot;&quot;;\nforeach ($results as $result) {\n    $html .= &#039;&lt;article&gt;&#039;;\n    $html .= &#039;&lt;h2&gt;&lt;a href=&quot;&#039;.get_permalink($result-&gt;ID).&#039;&quot;&gt;&#039;.apply_filters(&#039;the_title&#039;, $result-&gt;post_title).&#039;&lt;\/a&gt;&lt;\/h2&gt;&#039;;\n    $html .= &#039;&#039;;\n    $html .= &#039;&lt;\/article&gt;&#039;;\n}\necho $html;\n?&gt;<\/code><\/pre>\n<p>\u2191\u203b\u3053\u306e\u307e\u307e\u306e\u30b3\u30fc\u30c9\u3067\u5b9f\u884c\u3057\u300c\u3082\u3063\u3068\u8868\u793a\u300d\u30af\u30ea\u30c3\u30af\u3067\u306f&#8221;\u6700\u65b0&#8221;\u8a18\u4e8b\u304b\u3089\u6570\u3048\u30666\uff5e10\u756a\u76ee\u306e\u8a18\u4e8b\u304c\u8aad\u307f\u8fbc\u307e\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002<br \/>\n\u672c\u5f53\u306fsingle.php\u3067\u30c7\u30d5\u30a9\u8868\u793a\u3057\u3066\u3044\u308b\u30ea\u30b9\u30c8\u306e\u7d9a\u304d\u3092\u8aad\u307f\u8fbc\u307f\u305f\u3044\u3002<br \/>\n\uff08\u7d9a\u304d\u2192\u904e\u53bb\u8a18\u4e8b\u30ea\u30b9\u30c8\u306e6\uff5e10\u756a\u76ee\u8aad\u307f\u8fbc\u307f\u3001\u4ee5\u5f8c\u7d9a\u304d\uff09<\/p>\n<p>more-disp.php\u306e$sql\u767a\u884c\u306e\u969b\u306bWHERE\u306b<br \/>\n<code>AND $wpdb-&gt;posts.post_date &lt; \u300e\u8868\u793a\u4e2d\u306e\u8a18\u4e8b\u306epost_data\u300f<\/code><br \/>\n\u3092\u5165\u308c\u308c\u3070\u3046\u307e\u304f\u904e\u53bb\u306e\u8a18\u4e8b\u306e\u307f\u3067\u9806\u756a\u306b\u8aad\u307f\u8fbc\u307f\u3067\u304d\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u8003\u3048\u307e\u3057\u305f\u3002<\/p>\n<p>\u3057\u304b\u3057\u300e\u8868\u793a\u4e2d\u306e\u8a18\u4e8b\u306epost_data\u300f\u3092\u3046\u307e\u304f\u5909\u6570\u3067\u6307\u5b9a\u3067\u304d\u305a\u884c\u304d\u8a70\u3063\u3066\u307e\u3059\u3002<br \/>\n\u30a2\u30c9\u30d0\u30a4\u30b9\u306a\u3069\u9802\u3051\u307e\u3059\u3068\u52a9\u304b\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"template":"","class_list":["post-168314","topic","type-topic","status-closed","hentry"],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/168314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/topic\/168314\/revisions"}],"wp:attachment":[{"href":"https:\/\/ja.wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=168314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}