{"id":323,"date":"2008-08-27T08:38:19","date_gmt":"2008-08-27T00:38:19","guid":{"rendered":"https:\/\/www.wopus.org\/?p=323"},"modified":"2008-08-27T08:38:19","modified_gmt":"2008-08-27T00:38:19","slug":"rewrite-static-htm-paging","status":"publish","type":"post","link":"https:\/\/wopus.org\/?p=323","title":{"rendered":"\u5de7\u5999\u7f8e\u5316\u9759\u6001\u5316\u6587\u7ae0\u5206\u9875\u94fe\u63a5\u7ed3\u6784"},"content":{"rendered":"<p>\u524d\u5929\u548c\u5927\u5bb6\u5206\u4eab\u7684\u201c<a href=\"https:\/\/www.wopus.org\/how-to-relize-article-paging.html\" target=\"_blank\">\u5982\u4f55\u5b9e\u73b0Wordpress\u6587\u7ae0\u5206\u9875<\/a>\u201d\u53cd\u54cd\u5f88\u597d\uff0c\u4f46\u73b0\u5728\u5f88\u591aWPer\u90fd\u9759\u6001\u5316\u4e86\u81ea\u5df1\u7684\u7684Blog\uff0c<a href=\"https:\/\/www.wopus.org\/\" target=\"_blank\">Wopus\u4e2d\u6587\u5e73\u53f0<\/a>\u4e5f\u4e00\u6837\uff0c\u91c7\u7528\u4e86\u201c%postname%.html\u201d\u8fd9\u6837\u7684\u94fe\u63a5\u5f62\u5f0f\uff0c\u5206\u9875\u540e\u5c31\u53d8\u6210\u4e86\u201cpostname.html\/2\u201d\u7684\u5f62\u5f0f\uff0c\u76f8\u5f53\u4e0d\u7f8e\u89c2\uff0c\u6211\u4eec\u9700\u8981\u201cpostname-2.html\u201d\u8fd9\u6837\u7684\u5f62\u5f0f\uff0c\u6765\uff0c\u52a8\u4e24\u4e2a\u5c0f\u624b\u672f\uff1a<\/p>\n<ol>\n<li><strong>\u4fee\u6539wp-includes\/rewrite.php \u6587\u4ef6<\/strong><\/li>\n<p>\u627e\u5230 <coolcode linenum=\"off\">$rewrite = array_merge($rewrite, array($match => $query))<\/coolcode><br \/>\n \u5728\u8fd9\u884c\u4ee3\u7801\u4e4b\u524d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<br \/>\n<coolcode><br \/>\nif (strpos($match, &#8216;.html&#8217;) !== false &#038;&#038; strpos($query, &#8216;&#038;page=&#8217;) !== false) {<br \/>\n  $match = str_replace(&#8216;(\/[0-9]+)?\/?$&#8217;, &#8216;$&#8217;, $match);<br \/>\n  $rewrite = array_merge($rewrite, array(str_replace(&#8216;([^\/]+).html&#8217;, &#8216;([^\/]+)-([0-9]+).html&#8217;, $match) => $query));<br \/>\n}<br \/>\n<\/coolcode><\/p>\n<li><strong>wp-includes\/post-template.php \u6587\u4ef6<\/strong><\/li>\n<p>\u627e\u5230wp_link_pages\u51fd\u6570\uff0c\u7528\u4ee5\u4e0b\u4ee3\u7801\u66ff\u4ee3\u4e4b\uff1a<br \/>\n<!--more--><br \/>\n<coolcode><br \/>\n< ?php\n\/*\n \u4fee\u6539\u9875\u9762\u94fe\u63a5\n*\/\nfunction alter_page_link($link, $pagenum){\n  return str_replace(\".html\", \"-$pagenum.html\", $link);\t\n}\n\n\/*\n \u5305\u542b\u5728 \/ *=================* \/ \u4e4b\u95f4\u7684\u4ee3\u7801\u4f5c\u8fc7\u4fee\u6539\n*\/\nfunction wp_link_pages($args = '') {\n  $defaults = array(\n    'before' => &#8216;<\/p>\n<p>&#8216; . __(&#8216;Pages:&#8217;), &#8216;after&#8217; => &#8216;<\/p>\n<p>&#8216;,<br \/>\n    &#8216;next_or_number&#8217; => &#8216;number&#8217;, &#8216;nextpagelink&#8217; => __(&#8216;Next page&#8217;),<br \/>\n    &#8216;previouspagelink&#8217; => __(&#8216;Previous page&#8217;), &#8216;pagelink&#8217; => &#8216;%&#8217;,<br \/>\n    &#8216;more_file&#8217; => &#8221;, &#8216;echo&#8217; => 1<br \/>\n  );<\/p>\n<p>  $r = wp_parse_args( $args, $defaults );<br \/>\n  extract( $r, EXTR_SKIP );<\/p>\n<p>  global $post, $id, $page, $numpages, $multipage, $more, $pagenow;<br \/>\n  if ( $more_file != &#8221; )<br \/>\n    $file = $more_file;<br \/>\n  else<br \/>\n    $file = $pagenow;<\/p>\n<p>  $output = &#8221;;<\/p>\n<p>  \/*=================*\/<br \/>\n  \/* \u4f18\u5316\u4e00\u4e0b\uff0c\u592a\u591a\u91cd\u590d\u8c03\u7528\u4e86-_-! *\/<br \/>\n  $permalink_structure = get_option(&#8216;permalink_structure&#8217;);<br \/>\n  $not_public_post = in_array($post->post_status, array(&#8216;draft&#8217;, &#8216;pending&#8217;));<br \/>\n  $permalink = get_permalink();<\/p>\n<p>  \/* \u5224\u65ad\u6c38\u4e45\u94fe\u63a5\u683c\u5f0f\u662f\u5426\u652f\u6301\u9759\u6001\u5316 *\/<br \/>\n  $using_static_permalink = strpos($permalink, &#8216;.html&#8217;) !== false ? true : false;<br \/>\n  \/*=================*\/<\/p>\n<p>  if ( $multipage ) {<br \/>\n    if ( &#8216;number&#8217; == $next_or_number ) {<br \/>\n      $output .= $before;<br \/>\n      for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {\n        $j = str_replace('%',\"$i\",$pagelink);\n        $output .= ' ';\n        if ( ($i != $page) || ((!$more) &#038;&#038; ($page==1)) ) {\n          if ( 1 == $i ) {\n            $output .= '<a href=\"' . $permalink . '\">&#8216;;<br \/>\n          } else {<br \/>\n            \/*=================*\/<br \/>\n            if ( &#8221; == $permalink_structure || $not_public_post ) {<br \/>\n              $output .= &#8216;<a href=\"' . $permalink . '&amp;page=' . $i . '\">&#8216;;<br \/>\n            } else {<br \/>\n              if (!$using_static_permalink) {<br \/>\n                $output .= &#8216;<\/a><a href=\"' . trailingslashit($permalink) . user_trailingslashit($i, 'single_paged') . '\">&#8216;;<br \/>\n              } else {<br \/>\n                $output .= &#8216;<\/a><a href=\"' . alter_page_link($permalink, $i) . '\">&#8216;;<br \/>\n              }<br \/>\n            }<br \/>\n            \/*=================*\/<br \/>\n          }<br \/>\n        }<br \/>\n        $output .= $j;<br \/>\n        if ( ($i != $page) || ((!$more) &#038;&#038; ($page==1)) )<br \/>\n          $output .= &#8216;<\/a>&#8216;;<br \/>\n      }<br \/>\n      $output .= $after;<br \/>\n    } else {<br \/>\n      if ( $more ) {<br \/>\n        $output .= $before;<br \/>\n        $i = $page &#8211; 1;<br \/>\n        if ( $i &#038;&#038; $more ) {<br \/>\n          if ( 1 == $i ) {<br \/>\n            $output .= &#8216;<a href=\"' . $permalink . '\">&#8216; . $previouspagelink . &#8216;<\/a>&#8216;;<br \/>\n          } else {<br \/>\n            \/*=================*\/<br \/>\n            if ( &#8221; == $permalink_structure || $not_public_post ) {<br \/>\n              $output .= &#8216;<a href=\"' . $permalink . '&amp;page=' . $i . '\">&#8216; . $previouspagelink . &#8216;<\/a>&#8216;;<br \/>\n            } else {<br \/>\n              if (!$using_static_permalink) {<br \/>\n                $output .= &#8216;<a href=\"' . trailingslashit($permalink) . user_trailingslashit($i, 'single_paged') . '\">&#8216; . $previouspagelink . &#8216;<\/a>&#8216;;<br \/>\n              } else {<br \/>\n                $output .= &#8216;<a href=\"' . alter_page_link($permalink, $i) . '\">&#8216; . $previouspagelink . &#8216;<\/a>&#8216;;<br \/>\n              }<br \/>\n            }<br \/>\n            \/*=================*\/<br \/>\n          }<br \/>\n        }<br \/>\n        $i = $page + 1;<br \/>\n        if ( $i < = $numpages &#038;&#038; $more ) {\n          if ( 1 == $i ) {\n            $output .= '<a href=\"' . $permalink . '\">&#8216; . $nextpagelink . &#8221;;<br \/>\n          } else {<br \/>\n            \/*=================*\/<br \/>\n            if ( &#8221; == $permalink_structure || $not_public_post ) {<br \/>\n              $output .= &#8216;<a href=\"' . $permalink . '&amp;page=' . $i . '\">&#8216; . $nextpagelink . &#8216;<\/a>&#8216;;<br \/>\n            } else {<br \/>\n              if (!$using_static_permalink) {<br \/>\n                $output .= &#8216;<a href=\"' . trailingslashit($permalink) . user_trailingslashit($i, 'single_paged') . '\">&#8216; . $nextpagelink . &#8216;<\/a>&#8216;;<br \/>\n              } else {<br \/>\n                $output .= &#8216;<a href=\"' . alter_page_link($permalink, $i) . '\">&#8216; . $nextpagelink . &#8216;<\/a>&#8216;;<br \/>\n              }<br \/>\n            }<br \/>\n            \/*=================*\/<br \/>\n          }<br \/>\n        }<br \/>\n        $output .= $after;<br \/>\n      }<br \/>\n    }<br \/>\n  }<\/p>\n<p>  if ( $echo )<br \/>\n    echo $output;<\/p>\n<p>  return $output;<br \/>\n}<br \/>\n?><br \/>\n<\/coolcode><\/p>\n<\/ol>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u5728Wordpress2.6\u4e0b\u6d4b\u8bd5\u901a\u8fc7\uff0c\u4ee3\u7801\u6765\u81ea<a href=\"http:\/\/www.voidman.com\/2008\/03\/create-static-html-files-for-paged-post.html\" target=\"_blank\">Voidman<\/a><br \/>\n<strong>\u6ce8\u610f\uff1a<\/strong><br \/>\n1\u3001\u5f53\u4f60\u4fee\u6539\u5b8c\u6210\u540e\uff0c\u53ef\u80fd\u9700\u8981\u5230\u540e\u53f0\u8bbe\u7f6e\u91cc\u91cd\u65b0\u4fee\u6539\u4e00\u6b21\u201c\u6c38\u4e45\u94fe\u63a5\u5f62\u5f0f\u201d\uff0c\u65e0\u9700\u6539\u52a8\u8bbe\u7f6e\uff0c\u53ea\u9700\u70b9\u4e00\u4e0b\u201c\u66f4\u65b0\u201d\u3002\u5426\u5219\u4f1a\u51fa\u73b0404\u9519\u8bef\u3002<br \/>\n2\u3001\u82e5\u6ca1\u6709\u9759\u6001\u5316\u3001\u4f2a\u9759\u6001\u5316\u8fc7Wordpress\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u91c7\u7528&#8221;%postname%.html&#8221;\u8fd9\u6837\u7684\u94fe\u63a5\u5f62\u5f0f\uff0c\u8bf7\u4e0d\u8981\u8fd9\u6837\u4fee\u6539\uff0c\u5426\u5219\u4f1a\u51fa\u73b0\u201c404\u201d\u9519\u8bef\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u5929\u548c\u5927\u5bb6\u5206\u4eab\u7684\u201c\u5982\u4f55\u5b9e\u73b0Wordpress\u6587\u7ae0\u5206\u9875\u201d\u53cd\u54cd\u5f88\u597d\uff0c\u4f46\u73b0\u5728\u5f88\u591aWPer\u90fd\u9759\u6001\u5316\u4e86\u81ea\u5df1\u7684\u7684Blog\uff0cWopus\u4e2d\u6587\u5e73\u53f0\u4e5f\u4e00\u6837\uff0c\u91c7\u7528\u4e86\u201c%postname%.html\u201d\u8fd9\u6837\u7684\u94fe\u63a5\u5f62\u5f0f\uff0c\u5206\u9875\u540e\u5c31\u53d8\u6210\u4e86\u201cpostname.html\/2\u201d\u7684\u5f62\u5f0f\uff0c\u76f8\u5f53\u4e0d\u7f8e\u89c2\uff0c\u6211\u4eec\u9700\u8981\u201cpostname-2.html\u201d\u8fd9\u6837\u7684\u5f62\u5f0f\uff0c\u6765\uff0c\u52a8\u4e24\u4e2a\u5c0f\u624b\u672f\uff1a \u4fee\u6539wp-includes\/rewrite.php \u6587\u4ef6 \u627e\u5230 $rewrite = array_merge($rewrite, array($match => $query)) \u5728\u8fd9\u884c\u4ee3\u7801\u4e4b\u524d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a if (strpos($match, &#8216;.html&#8217;) !== false &#038;&#038; strpos($query, &#8216;&#038;page=&#8217;) !== false) { $match = str_replace(&#8216;(\/[0-9]+)?\/?$&#8217;, &#8216;$&#8217;, $match); $rewrite = array_merge($rewrite, array(str_replace(&#8216;([^\/]+).html&#8217;, &#8216;([^\/]+)-([0-9]+).html&#8217;, $match) => $query)); } wp-includes\/post-template.php \u6587\u4ef6 \u627e\u5230wp_link_pages\u51fd\u6570\uff0c\u7528\u4ee5\u4e0b\u4ee3\u7801\u66ff\u4ee3\u4e4b\uff1a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[313,806,929],"class_list":["post-323","post","type-post","status-publish","format-standard","hentry","category-tech","tag-wordpress","tag-wordpress-article-page","tag-929"],"_links":{"self":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts\/323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=323"}],"version-history":[{"count":0,"href":"https:\/\/wopus.org\/index.php?rest_route=\/wp\/v2\/posts\/323\/revisions"}],"wp:attachment":[{"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wopus.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}