我有个问题。我正在使用一个自定义分类法运行WP 3.05。
以下是创建分类法的代码:
function create_property_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'Property Types\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Property Type\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Property Types\' ),
\'all_items\' => __( \'All Property Types\' ),
\'parent_item\' => __( \'Parent Property Type\' ),
\'parent_item_colon\' => __( \'Parent Property Type:\' ),
\'edit_item\' => __( \'Edit Property Typee\' ),
\'update_item\' => __( \'Update Property Type\' ),
\'add_new_item\' => __( \'Add New Property Type\' ),
\'new_item_name\' => __( \'New Property Type\' ),
\'menu_name\' => __( \'Property Type\' ),
);
register_taxonomy(\'property_type\',array(\'sbproperty\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => true,
));
global $wp_rewrite;
$wp_rewrite->extra_permastructs[\'property_type\'] = array(\'%property_type%\', EP_NONE);
}
我使用了额外的permastruct,因此分类法只出现在类似url的基本站点上。com/taxonomy slug代替site。com/分类/分类slug
我还使用顶级cats插件对原始分类法执行相同的操作。
但这与我的页面产生了冲突。当我删除permastruct时,页面会加载到漂亮的permalink上,但如果我的permastruct没有加载,那么所有顶级页面都会得到404。
最合适的回答,由SO网友:Liam Bailey 整理而成
抱歉,伙计们,这正在成为一种习惯,但我找到了一个解决方案,如下所示:
在分类法注册中将rewrite设置为false:register\\u taxonomy(\'property\\u type\',array(\'sbproperty\'),array(\'hierarchy\'=>true,\'labels\'=>$labels,\'show\\u ui\'=>true,\'query\\u var\'=>true,\'rewrite\'=>false));
创建我自己的规则
add_filter(\'rewrite_rules_array\',\'wp_insertMyRewriteRules\');
add_filter(\'init\',\'flushRules\');
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules["([a-z]+)-in-turkey-for-sale/?$"] \'index.php?property_type=$matches[1]-in-turkey-for-sale\';
return $newrules + $rules;
}