{"id":1810,"date":"2013-04-09T08:38:11","date_gmt":"2013-04-09T00:38:11","guid":{"rendered":"https:\/\/sdeno.com\/?p=1810"},"modified":"2013-04-09T08:55:27","modified_gmt":"2013-04-09T00:55:27","slug":"wordpress%e9%a6%96%e9%a1%b5%e4%bd%bf%e7%94%a8ajax%e5%ae%9e%e7%8e%b0%e5%88%86%e9%a1%b5%e6%96%b9%e6%b3%95%ef%bc%88%e9%9d%9ewordpress%e6%8f%92%e4%bb%b6%ef%bc%89","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=1810","title":{"rendered":"wordpress\u9996\u9875\u4f7f\u7528ajax\u5b9e\u73b0\u5206\u9875\u65b9\u6cd5\uff08\u975ewordpress\u63d2\u4ef6\uff09"},"content":{"rendered":"<p>wordpress\u9996\u9875\u4f7f\u7528ajax\u5b9e\u73b0\u7ffb\u9875\u65b9\u6cd5\u3002\u90a3\u4e48\u6211\u4eec\u4e3a\u4ec0\u4e48\u8981\u5bf9wordpress\u535a\u5ba2\u7684\u9996\u9875\u8fdb\u884cajax\u5206\u9875\uff0c\u6709\u4eba\u8bf4wordpress\u9996\u9875\u91c7\u7528ajax\u5206\u9875\u53ef\u4ee5\u51cf\u8f7b\u670d\u52a1\u5668\u6570\u636e\u63d0\u4ea4\u7684\u6570\u91cf,\u4f7f\u7528ajax\u5b9e\u73b0\u7ffb\u9875\u53ea\u4f1a\u5237\u65b0\u7528\u6237\u60f3\u8981\u7684\u5185\u5bb9\u533a\u4f53\u9a8c\u5ea6\u4e5f\u5c31\u80fd\u5f97\u5230\u5f88\u5927\u7a0b\u5ea6\u7684\u63d0\u5347\u3002\u7279\u522b\u662f\u5bf9\u4e8e\u5927\u591a\u6570\u56fe\u7247\u8f83\u591a\u7684\u7f51\u7ad9\u5982\u679c\u4e00\u6b21\u5237\u65b0\u7ffb\u9875\u65f6\u4e0d\u4ec5\u52a0\u8f7d\u56fe\u7247\u533a\u540c\u65f6\u4e5f\u52a0\u8f7d\u4e86\u6574\u7ad9\u8fd9\u6837\u6ca1\u6709\u5fc5\u8981,\u52a0\u8f7d\u901f\u5ea6\u8f83\u6162\u7684Blog,AJAX\u662f\u4e2a\u975e\u5e38\u4e0d\u9519\u7684\u9009\u62e9\u3002<br \/>\nwordpress\u9996\u9875ajax\u5206\u9875\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b\uff1a<br \/>\n1\u3001\u9996\u5148\u5f53\u7136\u662f\u52a0\u8f7djquery\u5e93,\u5982\u679c\u60a8\u7684\u4e3b\u9898\u5df2\u7ecf\u52a0\u8f7d\u4e86jquery\u5e93,\u5219\u672c\u6b65\u9aa4\u53ef\u4ee5\u7565\u53bb,jquery\u7248\u672c\u4fdd\u6301\u57281.2.3\u4ee5\u4e0a\u3002<br \/>\n[code]&lt;script type=&#8221;text\/javascript&#8221; src=&#8221;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.6.4\/jquery.min.js&#8221;&gt;&lt;\/script&gt;[\/code]<br \/>\n2\u3001\u5c06\u4e0b\u9762\u90a3\u6bb5JS\u4fdd\u5b58\u4e3aindex_ajax_navi.js,\u5e76\u5728header\u90e8\u5206\u4e2d\u5f15\u7528\u52a0\u8f7d\uff0c\u4f46\u662f\u8981\u5728jquery\u5e93\u4e4b\u540e\u52a0\u8f7d:<\/p>\n<p>[code]var navi=&#8217;.pagenavi&#8217;;\/\/\u53d8\u91cf\u58f0\u660e .pagenavi\u6362\u6210\u4f60\u4e3b\u9898\u4e2d\u5206\u9875\u7684CSS\u7c7b\u540d<br \/>\nvar navi_a=&#8217;.pagenavi a&#8217;;\/\/\u53d8\u91cf\u58f0\u660e .pagenavi a\u6362\u6210\u4f60\u4e3b\u9898\u4e2d\u5206\u9875a\u6807\u7b7e\u7684CSS\u7c7b\u540d<br \/>\nvar content=&#8217;#content&#8217;;\/\/\u53d8\u91cf\u58f0\u660e #content\u6362\u6210\u4f60\u4e3b\u9898\u4e2d\u7528\u4e8eAJAX\u5237\u65b0\u90e8\u5206\u7684ID\u540d<\/p>\n<p>$(document).ready(function index_ajax_navi (){<br \/>\n$(navi_a).click(function() {<br \/>\nvar z = $(this).attr(&#8220;href&#8221;);<br \/>\n$.ajax({<br \/>\nurl: z,<br \/>\ntype:&#8221;POST&#8221;,<br \/>\ndata:&#8221;action=index_ajax_navi&#8221;,<br \/>\nbeforeSend:function()<br \/>\n{<br \/>\ndocument.body.style.cursor = &#8216;wait&#8217;;<br \/>\nvar C=1.0;<br \/>\n$(content).css({opacity:C,MozOpacity:C,KhtmlOpacity:C,filter:&#8217;alpha(opacity=&#8217; + C * 100 + &#8216;)&#8217;});<br \/>\n$(navi).html(&#8216;&lt;img src=&#8221;loading\u56fe\u7247\u7684\u8def\u5f84&#8221;&gt;&lt;a&gt;\u6b63\u5728\u52a0\u8f7d\u4e2d&#8230;&lt;\/a&gt;&#8217;);<br \/>\n},<br \/>\nerror: function(request)<br \/>\n{<br \/>\nalert(request.responseText);<br \/>\n},<br \/>\nsuccess: function (data)<br \/>\n{<br \/>\n$(content).html(data);<br \/>\ndocument.body.style.cursor = &#8216;auto&#8217;;<br \/>\nvar C=1; \/\/\u8bbe\u7f6e\u7ffb\u9875\u7684\u65f6\u5019,AJAX\u90e8\u5206\u7684\u900f\u660e\u5ea6,\u53ef\u4ee5\u4e3a0.5;0.6\u7b49<br \/>\n$(content).css({opacity:C,MozOpacity:C,KhtmlOpacity:C,filter:&#8217;alpha(opacity=&#8217; + C * 100 + &#8216;)&#8217;});<br \/>\n\/\/$body.animate({ scrollTop: &#8216;0px&#8217;}, 1000);<br \/>\nindex_ajax_navi();\/\/\u7ffb\u9875\u540eDOM\u53d1\u751f\u53d8\u5316,\u91cd\u65b0\u7ed1\u5b9a\u8be5\u51fd\u6570<br \/>\n\/\/$body.animate( { scrollTop: $(content).offset().top &#8211; 150}, 1000);<br \/>\n\/\/$body.animate({ scrollTop: &#8216;0px&#8217;}, 1000);<br \/>\njQuery(&#8216;html, body&#8217;).animate({scrollTop:$(content).offset().top &#8211; 100}, &#8216;slow&#8217;);<br \/>\n}<br \/>\n});<br \/>\nreturn false;<br \/>\n});<br \/>\n})[\/code]<br \/>\n\u4e0a\u9762\u4ee3\u7801\u4e2d\u7684\u76f8\u5173ID\uff0c\u9700\u8981\u6839\u636e\u4f60\u81ea\u5df1\u4e3b\u9898\u4fee\u6539\u4e00\u4e0b<br \/>\n3\u3001\u5c06\u5982\u4e0b\u4ee3\u7801\u5199\u5230\u4f60\u7684\u540e\u53f0functions.php\u4e2d<\/p>\n<p>[code]function index_ajax_navi(){<br \/>\nif( isset($_POST[&#8216;action&#8217;])&amp;&amp; $_POST[&#8216;action&#8217;] == &#8216;index_ajax_navi&#8217;){<br \/>\ninclude_once TEMPLATEPATH.&#8217;\/index_list.php&#8217;; \/\/\u6ce8\u610f\u4fee\u6539\u4e3a\u4f60\u81ea\u5df1\u7684\u6587\u4ef6\u7684\u4f4d\u7f6e<br \/>\ndie();<br \/>\n}else{<br \/>\nreturn;<br \/>\n}<br \/>\n}<br \/>\nadd_action(&#8216;template_redirect&#8217;, &#8216;index_ajax_navi&#8217;);[\/code]<br \/>\n4\u3001\u628a\u4f60\u4e3b\u9898\u7684index.php\u5199\u6210\u4e24\u4e2a\u6587\u4ef6\uff0c\u4e00\u4e2a\u662f\u6846\u67b6\u6587\u4ef6\uff0c\u4e00\u4e2a\u662findex_list.php\u3002\u662fajax\u8bf7\u6c42\u9700\u8981\u91cd\u65b0\u52a0\u8f7d\u7684\u9875\u9762\u3002\u8fd9\u91cc\u8981\u6ce8\u610f\uff0c\u5e76\u4e0d\u662f\u8981\u5199\u6210\u8fd9\u4e2a\u6837\u5b50\uff0c\u8fd9\u662f\u4e00\u79cd\u601d\u60f3\u3002\u5c31\u662findex_list.php\u662f\u9700\u8981\u88ab\u91cd\u65b0\u52a0\u8f7d\u7684\uff0c\u6bcf\u4e2a\u4eba\u628a\u81ea\u5df1\u7684index.php\u9700\u8981\u5728\u70b9\u51fb\u9875\u9762\u4e4b\u540e\u91cd\u65b0\u52a0\u8f7d\u7684\u4e1c\u897f\u63d0\u51fa\u6765\uff0c\u5199\u5230index_list.php\u4e4b\u4e2d\u5373\u53ef\u3002<br \/>\nindex.php\u5199\u6210\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\uff08\u6bcf\u4e2a\u4eba\u7684\u4e3b\u9898\u90fd\u4e0d\u540c\uff0c\u8bf7\u81ea\u5df1\u4fee\u6539\uff09\uff1a<\/p>\n<p>[code]&lt;?php get_header(); ?&gt;<br \/>\n&lt;?php<br \/>\n$posts = query_posts($query_string . &#8216;&amp;orderby=date&amp;showposts=8&#8217;);<br \/>\npre_next();<br \/>\n?&gt;<br \/>\n<span style=\"color: #ff0000;\">&lt;div id=&#8221;content&#8221;&gt;<\/span><br \/>\n<span style=\"color: #ff0000;\"> &lt;?php include_once TEMPLATEPATH.&#8217;\/index_list.php&#8217;; ?&gt;<\/span><br \/>\n<span style=\"color: #ff0000;\"> &lt;\/div&gt;<\/span> &lt;!&#8211;end: content&#8211;&gt;<br \/>\n&lt;?php wp_reset_query(); ?&gt;<br \/>\n&lt;?php get_sidebar(); ?&gt;<br \/>\n&lt;?php get_footer(); ?&gt;[\/code]<br \/>\nindex_list.php\u5199\u6210\u8fd9\u4e2a\u6837\u5b50\uff1a<\/p>\n<p>[code]&lt;?php while (have_posts()) { the_post(); ?&gt;<\/p>\n<p>&lt;div class=&#8221;post&#8221; id=&#8221;post-&lt;?php the_ID(); ?&gt;&#8221;&gt;<br \/>\n&lt;div class=&#8221;title&#8221;&gt;&lt;a href=&#8221;&lt;?php the_permalink() ?&gt;&#8221; rel=&#8221;bookmark&#8221; title=&#8221;\u6253\u5f00 &lt;?php the_title_attribute(); ?&gt; \u5427\uff0c\u8fd8\u7b49\u4ec0\u4e48\uff1f&#8221;&gt;&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;\/h2&gt;&lt;\/a&gt;&lt;\/div&gt;<br \/>\n&lt;?php include (TEMPLATEPATH . &#8216;\/myad\/adindex.php&#8217;); ?&gt;<br \/>\n&lt;div class=&#8221;headline&#8221;&gt;<br \/>\n&lt;?php if(function_exists(&#8216;wp_thumbnails_for_homepage&#8217;)) { wp_thumbnails_for_homepage(); } ?&gt;<br \/>\n&lt;span&gt;&lt;?php the_time(&#8220;M&lt;b\\i\\g&gt;j&lt;\/b\\i\\g&gt;&#8221;) ?&gt;&lt;\/span&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;div class=&#8221;text&#8221; style=&#8221;margin: 0;&#8221;&gt;<br \/>\n&lt;?php the_content(&#8216;&lt;br \/&gt;continue reading &amp;raquo;&#8217;); ?&gt;&lt;\/div&gt;<br \/>\n&lt;div class=&#8221;postother&#8221; style=&#8221;background:#E7E7DA;&#8221;&gt;<br \/>\n&lt;span class=&#8221;category&#8221;&gt;&lt;?php the_category(&#8216;, &#8216;) ?&gt; &lt;\/span&gt;<br \/>\n&lt;span class=&#8221;comments&#8221;&gt;&lt;?php comments_popup_link(&#8216;\u6dfb\u52a0\u8bc4\u8bba&#8217;, &#8216;1\u6761\u8bc4\u8bba&#8217;, &#8216;%\u6761\u8bc4\u8bba&#8217;); ?&gt; &lt;\/span&gt;<br \/>\n&lt;span class=&#8221;hits&#8221;&gt;&lt;?php if(function_exists(&#8216;the_views&#8217;)) { the_views(); } ?&gt; &lt;\/span&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;?php } ?&gt;<br \/>\n&lt;div class=&#8221;pageNavi&#8221;&gt;<br \/>\n&lt;?php if (function_exists(&#8216;pagenavi&#8217;)) { pagenavi(); } ?&gt;<br \/>\n&lt;\/div&gt;[\/code]<br \/>\nok\uff0c\u73b0\u5728\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9e\u73b0\u9996\u9875\u7684ajax\u7ffb\u9875\u6548\u679c\u4e86\u3002\u4e0d\u8fc7\u6bcf\u4e2a\u4eba\u7684\u4e3b\u9898\u8bbe\u7f6e\u4e0d\u540c\uff0c\u4e0a\u9762\u90e8\u5206\u6b65\u9aa4\u4e2d\u6709\u4e9b\u5730\u65b9\u9700\u8981\u6839\u636e\u81ea\u5df1\u7684\u4e3b\u9898\u8bbe\u7f6e\u81ea\u5df1\u7684\u53c2\u6570\u3002\u7279\u522b\u662f\u5305\u542b\u5206\u9875\u94fe\u63a5\u7684div\u7684class\u3002\u6211\u8fd9\u91cc\u662f.pagenavi\u3002\u8fd8\u6709\u5c31\u662f\u5305\u542bindex_list.php\u7684 div id=\u201dcontent\u201d\uff0c\u9700\u8981\u5728js\u4e2d\u586b\u5165\u8fd9\u4e24\u4e2a\u5173\u952e\u7684div<\/p>\n","protected":false},"excerpt":{"rendered":"<p>wordpress\u9996\u9875\u4f7f\u7528ajax\u5b9e\u73b0\u7ffb\u9875\u65b9\u6cd5\u3002\u90a3\u4e48\u6211\u4eec\u4e3a\u4ec0\u4e48\u8981\u5bf9wordpress\u535a\u5ba2\u7684\u9996\u9875\u8fdb\u884cajax\u5206\u9875 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,11],"tags":[],"class_list":["post-1810","post","type-post","status-publish","format-standard","hentry","category-wordpress","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/1810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1810"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/1810\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}