{"id":681,"date":"2013-01-08T19:07:27","date_gmt":"2013-01-08T11:07:27","guid":{"rendered":"https:\/\/sdeno.com\/?p=681"},"modified":"2013-01-08T19:07:27","modified_gmt":"2013-01-08T11:07:27","slug":"wordpress-%e6%97%a0%e6%8f%92%e4%bb%b6%e5%ae%9e%e7%8e%b0%e6%96%87%e7%ab%a0%e5%88%86%e9%a1%b5%e5%af%bc%e8%88%aa","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=681","title":{"rendered":"wordpress \u65e0\u63d2\u4ef6\u5b9e\u73b0\u6587\u7ae0\u5206\u9875\u5bfc\u822a"},"content":{"rendered":"<p>wordpress \u65e0\u63d2\u4ef6\u663e\u793a\u6587\u7ae0\u9875\u7801\uff0c\u6548\u679c\u5c31\u8ddf\u672c\u7ad9\u4e00\u6837\u3002<\/p>\n<p>\u7f51\u4e0a\u6709\u63d2\u4ef6\u4f46\u662f\u5c0f\u7f16\u7684\u5b97\u65e8\u662f\u5c3d\u91cf\u4e0d\u7528\u63d2\u4ef6\uff0c\u4e0b\u9762\u4ecb\u7ecd\u6b65\u9aa4\uff1a<\/p>\n<p>1\uff0c\u5728functions.php\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>[code]function pagenav($query_string){<br \/>\nglobal $posts_per_page, $paged;<br \/>\n$my_query = new WP_Query($query_string .&#8221;&amp;posts_per_page=-1&#8243;);<br \/>\n$total_posts = $my_query-&gt;post_count;<br \/>\nif(empty($paged))$paged = 1;<br \/>\n$prev = $paged &#8211; 1;<br \/>\n$next = $paged + 1;<br \/>\n$range = 4; \/\/ only edit this if you want to show more page-links<br \/>\n$showitems = ($range * 2)+1;<\/p>\n<p>$pages = ceil($total_posts\/$posts_per_page);<br \/>\nif(1 != $pages){<br \/>\necho &#8220;&lt;div class=&#8217;pagination&#8217;&gt;&#8221;;<br \/>\necho ($paged &gt; 2 &amp;&amp; $paged+$range+1 &gt; $pages &amp;&amp; $showitems &lt; $pages)? &#8220;&lt;a href='&#8221;.get_pagenum_link(1).&#8221;&#8216;&gt;\u6700\u524d&lt;\/a&gt;&#8221;:&#8221;&#8221;;<br \/>\necho ($paged &gt; 1 &amp;&amp; $showitems &lt; $pages)? &#8220;&lt;a href='&#8221;.get_pagenum_link($prev).&#8221;&#8216;&gt;\u4e0a\u4e00\u9875&lt;\/a&gt;&#8221;:&#8221;&#8221;;<\/p>\n<p>for ($i=1; $i &lt;= $pages; $i++){<br \/>\nif (1 != $pages &amp;&amp;( !($i &gt;= $paged+$range+1 || $i &lt;= $paged-$range-1) || $pages &lt;= $showitems )){<br \/>\necho ($paged == $i)? &#8220;&lt;span class=&#8217;current&#8217;&gt;&#8221;.$i.&#8221;&lt;\/span&gt;&#8221;:&#8221;&lt;a href='&#8221;.get_pagenum_link($i).&#8221;&#8216; class=&#8217;inactive&#8217; &gt;&#8221;.$i.&#8221;&lt;\/a&gt;&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p>echo ($paged &lt; $pages &amp;&amp; $showitems &lt; $pages) ? &#8220;&lt;a href='&#8221;.get_pagenum_link($next).&#8221;&#8216;&gt;\u4e0b\u4e00\u9875&lt;\/a&gt;&#8221; :&#8221;&#8221;;<br \/>\necho ($paged &lt; $pages-1 &amp;&amp; $paged+$range-1 &lt; $pages &amp;&amp; $showitems &lt; $pages) ? &#8220;&lt;a href='&#8221;.get_pagenum_link($pages).&#8221;&#8216;&gt;\u6700\u540e&lt;\/a&gt;&#8221;:&#8221;&#8221;;<br \/>\necho &#8220;&lt;\/div&gt;\\n&#8221;;<br \/>\n}<br \/>\n}[\/code]<\/p>\n<p>2\uff0c\u9700\u8981\u663e\u793a\u7684\u5730\u65b9\uff0c\u8c03\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>[code]&lt;div id=&#8221;lie_biao&#8221;&gt;<br \/>\n&lt;?php pagenav($query_string); ?&gt;&lt;!&#8211;\u6587\u7ae0\u5217\u8868&#8211;&gt;<br \/>\n&lt;\/div&gt;[\/code]<\/p>\n<p>3\uff0cCSS\u6837\u5f0f\uff1a<\/p>\n<p>[code].pagination{ margin:0 10px 10px 15px;line-height:23px;text-align:center;}<br \/>\n.pagination span, .pagination a{font-size:12px;margin: 2px 6px 2px 0;border:1px solid #7e5025;color:#787878;padding:2px 5px 2px 5px;text-decoration:none;<br \/>\nfont-weight:bold;}<br \/>\n.pagination a:hover{background: #8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px 5px;}<br \/>\n.pagination .current{background: #8cb900;border:1px solid #436206;color:#fff;font-size:12px;padding:2px 5px 2px 5px;}<\/p>\n<p>#lie_biao{<br \/>\nmargin-top:3px;<br \/>\npadding-top:3px;<\/p>\n<p>}[\/code]<\/p>\n<p>\u5176\u4e2d\u7684functions.php\u6dfb\u52a0\u4ee3\u7801\u5904\u7684<\/p>\n<p>$range = 4;<\/p>\n<p>\u662f\u9996\u9875\u7684\u9ed8\u8ba4\u663e\u793a\u9875\u6570\u53ef\u4ee5\u81ea\u884c\u4fee\u6539\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>wordpress \u65e0\u63d2\u4ef6\u663e\u793a\u6587\u7ae0\u9875\u7801\uff0c\u6548\u679c\u5c31\u8ddf\u672c\u7ad9\u4e00\u6837\u3002 \u7f51\u4e0a\u6709\u63d2\u4ef6\u4f46\u662f\u5c0f\u7f16\u7684\u5b97\u65e8\u662f\u5c3d\u91cf\u4e0d\u7528\u63d2\u4ef6\uff0c\u4e0b\u9762\u4ecb\u7ecd\u6b65 [&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-681","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\/681","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=681"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}