我的URL格式如下:
http://domain.com/custom-post-type/category/cat-name/page/page-number
我需要提取:
cat-name
和page-number
所以在我的functions.php
, 我可以创建自定义重写规则:
function my_insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules[\'projects/category/(.+)/page/(\\d+)/?$\'] = \'index.php?post_type=project&project_cat=$matches[1]&paged=$matches[2]\';
return $newrules + $rules;
}
我试图使用以下表达式:
projects/category/(.+)/page/(\\d+)/?$
在本例中,这似乎可以正常工作(避开正斜杠):
http://rubular.com/r/5rzECsTexy然而,这似乎从来都不起作用,URL:
http://domain.com/projects/category/print
和http://domain.com/projects/category/print/page/2
似乎总是404。
我以前的重写规则projects/category/(.*/?)$
为该类别工作,但没有正确提取页码。
Edit自定义帖子类型注册码(在我的主题中function.php
)
// Custom Post Types
add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'project\',
array(
\'labels\' => array(
\'name\' => __( \'Projects\' ),
\'singular_name\' => __( \'Project\' )
),
\'public\' => true,
\'has_archive\' => true,
\'taxonomies\' => array(\'category\'),
\'rewrite\' => array(\'slug\' => \'projects\')
)
);
}