更改分页中的“Page”插件

时间:2012-07-01 作者:DarkGhostHunter

简单的问题。激活分页后,URL将更改为"site.com/page/2". 对于我的网站,这应该是"site.com/paggetto/2".

如何更改重写规则?我也想改变"author" 和其他变量。

4 个回复
最合适的回答,由SO网友:fuxia 整理而成

对于一些德语网站,我使用以下插件进行翻译pageseite (德语单词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 );
    }
}
请注意,在取消/激活时刷新重写规则only. 您需要在.htaccess 要将旧URL重定向到新URL,请执行以下操作:

RedirectMatch Permanent ^/(.*)/page/(.*) /$1/seite/$2

SO网友:DarkGhostHunter

计算出:

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\');
至少,这可以完成工作。

SO网友:Vitor Almeida

此功能将直接与您的翻译包一起使用,格式化您的新基础,并防止flush\\u rewrite\\u 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\');

SO网友:michalzuber

以下几点对我有用:

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\' );

结束

相关推荐

Pagination on custom query

我正在使用以下代码query_posts 要组合自定义搜索,请执行以下操作:$args = array( \'post_type\' => \'species\', \'meta_query\' => $meta_query, \'tax_query\' => $tax_query ); $meta_query 由以下几段代码组成:if (!empty($_POST[\"s_aquarium_H\"])) {