下面再给出其他几种格式,以供参考:
一、/%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)
文章挺不错的,写得很好
没事来瞄瞄.
不错不错,虽然网上有很多类似的,但博主的钻研劲头是难得的
进来参考一下。。
打开速度有些不给力。
呵呵,楼主说的很好的