WordPress单篇文章分页静态化错误的处理方法

下面再给出其他几种格式,以供参考:

一、/%year%/%monthnum%/%postname%.html

// 添加分页处理规则
function add_custom_post_rewrite_rules($rules) {
  $custom_rules = array(
    '([0-9]{4})/([0-9]{1,2})/([^/]+)-([0-9]+)\.html$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&page=$matches[4]',
  );
  $rules = array_merge($custom_rules, $rules);
Š  return $rules;
}
add_filter('post_rewrite_rules', 'add_custom_post_rewrite_rules');
Š// 修改分页链接
function my_wp_link_pages($args = '') {
  $args .= ($args ? '&' : '') . 'echo=0';
  $links = wp_link_pages($args);
  $links = preg_replace_callback('|([0-9]{4}/[0-9]{1,2}/)([^/]+)(\.html)(/)([0-9]+)|', 'custom_page_link', $links);
Š  echo $links;
}
Šfunction custom_page_link($matches) {
  return $matches[1].$matches[2].'-'.$matches[5].$matches[3];
}
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html/trackback/?$ index.php?year=$1&monthnum=$2&name=$3&tb=1 [L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?year=$1&monthnum=$2&name=$3&feed=$4 [L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})/([^/]+)\.html/(feed|rdf|rss|rss2|atom)/?$ index.php?year=$1&monthnum=$2&name=$3&feed=$4 [L]
</ifmodule>

二、/%year%/%monthnum%%day%/%postname%.html

// 添加分页处理规则
function add_custom_post_rewrite_rules($rules) {
  $custom_rules = array(
    '([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)-([0-9]+)\.html$' => 'index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&name=$matches[4]&page=$matches[5]',
  );
  $rules = array_merge($custom_rules, $rules);

  return $rules;
}
add_filter('post_rewrite_rules', 'add_custom_post_rewrite_rules');

// 修改分页链接
function my_wp_link_pages($args = '') {
  $args .= ($args ? '&' : '') . 'echo=0';
  $links = wp_link_pages($args);
  $links = preg_replace_callback('|([0-9]{4}/[0-9]{1,2}[0-9]{1,2}/)([^/]+)(\.html)(/)([0-9]+)|', 'custom_page_link', $links);

  echo $links;
}

function custom_page_link($matches) {
  return $matches[1].$matches[2].'-'.$matches[5].$matches[3];
}
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)\.html/trackback/?$ index.php?year=$1&monthnum=$2&day=$3&name=$4&tb=1 [L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)\.html/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5 [L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)\.html/(feed|rdf|rss|rss2|atom)/?$ index.php?year=$1&monthnum=$2&day=$3&name=$4&feed=$5 [L]
RewriteRule ^([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)\.html/page/?([0-9]{1,})/?$ index.php?year=$1&monthnum=$2&day=$3&name=$4&paged=$5
RewriteRule ^([0-9]{4})/([0-9]{1,2})([0-9]{1,2})/([^/]+)\.html/([0-9]+)/?$ index.php?year=$1&monthnum=$2&day=$3&name=$4&page=$5
</IfModule>


0%(0)

100%(3)
发表评论?

25 条评论。

  1. 文章挺不错的,写得很好

  2. 不错不错,虽然网上有很多类似的,但博主的钻研劲头是难得的

  3. 呵呵,楼主说的很好的

回复给 bluehost ¬
取消回复

*