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

五、/html/%post_id%.html

// 添加分页处理规则
function add_custom_post_rewrite_rules($rules) {
  $custom_rules = array(
    'html/([0-9]+)-([0-9]+)\.html$' => 'index.php?p=$matches[1]&page=$matches[2]',
  );
  $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('|(html/)([0-9]+)(\.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 ^html/([0-9]+)\.html/trackback/?$ index.php?p=$1&tb=1 [L]
RewriteRule ^html/([0-9]+)\.html/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?p=$1&feed=$2 [L]
RewriteRule ^html/([0-9]+)\.html/(feed|rdf|rss|rss2|atom)/?$ index.php?p=$1&feed=$2 [L]
RewriteRule ^html/([0-9]+)\.html/page/?([0-9]{1,})/?$ index.php?p=$1&paged=$2
RewriteRule ^html/([0-9]+)\.html/([0-9]+)/?$ index.php?p=$1&page=$2
</IfModule>

六、/html/%post_id%.html

// 添加分页处理规则
function add_custom_post_rewrite_rules($rules) {
  $custom_rules = array(
    'html/([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('|(html/[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 ^html/([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 ^html/([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 ^html/([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 ^html/([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 ^html/([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)
上一页 1 2 3 4
发表评论?

25 条评论。

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

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

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

回复给 酒店管理培训资料 ¬
取消回复

*