Answers:
对于某些德语网站,我使用以下插件将其翻译page
为seite
(德语单词page
):
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Page to Seite
* Description: Ersetzt <code>/page/</code> durch <code>/seite/</code>.
* Author: Fuxia Scholz
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
if ( ! function_exists( 't5_page_to_seite' ) )
{
register_activation_hook( __FILE__ , 't5_flush_rewrite_on_init' );
register_deactivation_hook( __FILE__ , 't5_flush_rewrite_on_init' );
add_action( 'init', 't5_page_to_seite' );
function t5_page_to_seite()
{
$GLOBALS['wp_rewrite']->pagination_base = 'seite';
}
function t5_flush_rewrite_on_init()
{
add_action( 'init', 'flush_rewrite_rules', 11 );
}
}
请注意,仅在de / activation 时才刷新重写规则。您将需要一个单独的重写规则,.htaccess
以将旧的URL重定向到新的URL:
RedirectMatch Permanent ^/(.*)/page/(.*) /$1/seite/$2
想通了:
function re_rewrite_rules() {
global $wp_rewrite;
// $wp_rewrite->author_base = $author_slug;
// print_r($wp_rewrite);
$wp_rewrite->author_base = 'autor';
$wp_rewrite->search_base = 'buscar';
$wp_rewrite->comments_base = 'comentarios';
$wp_rewrite->pagination_base = 'pagina';
$wp_rewrite->flush_rules();
}
add_action('init', 're_rewrite_rules');
至少,这可以完成工作。
$wp_rewrite->flush_rules();
性能方面的成本极其高昂,因此永远不要在上面使用它init
,更好的选择是访问Permalink选项页面,并保存几次更改,以便为您刷新。
此函数将直接与您的翻译包一起使用,设置新库的格式,并避免多次运行flush_rewrite_rules函数,从而避免博客性能下降。
function my_change_rewrite_base() {
global $wp_rewrite;
$bases = array(
'author' => __('Author'),
'search' => __('Search'),
'comments' => __('Comments)',
'pagination' => __('Page')
);
foreach ($bases AS $key => $base) {
$wp_rewrite->{$key} = remove_accents(mb_strtolower($base));
}
if ( ! get_option('my_change_rewrite_base_flushed', false) ) {
flush_rewrite_rules();
update_option( 'my_change_rewrite_base_flushed', time());
}
}
add_action('init', 'my_change_rewrite_base');
以下为我工作:
function nw_strana() {
$GLOBALS['wp_rewrite']->pagination_base = 'strana';
}
add_action( 'init', 'nw_strana' );
function nw_rewrite( $rules ) {
$new_rules = array(
'obchod/strana/([0-9]{1,})/?$' => 'index.php?post_type=product&paged=$matches[1]',
);
$rules = array_merge( $new_rules, $rules );
return $rules;
}
add_filter( 'rewrite_rules_array', 'nw_rewrite' );