簡単な質問。ページネーションがアクティブになると、URLはに変わります"site.com/page/2"。私のサイトでは、これはである必要があります"site.com/paggetto/2"。
書き換えルールを変更するにはどうすればよいですか?"author"他の変数も変更したいです。
簡単な質問。ページネーションがアクティブになると、URLはに変わります"site.com/page/2"。私のサイトでは、これはである必要があります"site.com/paggetto/2"。
書き換えルールを変更するにはどうすればよいですか?"author"他の変数も変更したいです。
回答:
ドイツ語の一部のサイトでは、次のプラグインを使用して翻訳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' );