最近我发现我可以在with-front=>false中使用register_post_type()参数。因此,我去改变了我的自定义post类型的子弹,并做了一个flush_rewrite_rules()。现在,我的2个自定义post类型正在使用所需的URL,而2个则不使用。唯一的区别是,工作的2和其他,是他们也有自定义分类法。这是我的functions.php文件中的代码。知道我做错什么了吗?
add_action('init','ASH_addtaxonomies');
add_action('init','ASH_addposttypes');
function ASH_addtaxonomies(){
register_taxonomy('ash_weave_structure', null,
array('labels'=>array('name'=>'Weave Structures',
'singular_name'=>'Structure'),
'public'=>true,
'hierarchical'=>true,
'rewrite'=>array('slug'=>'samples_weaving/structures', 'with-front'=>false),
'query_var'=>true
)
);
register_taxonomy('ash_weave_technique', null,
array( 'labels'=>array( 'name'=>'Weaving Techniques',
'singular_name'=>'Technique'),
'public'=>true,
'hierarchical'=>false,
'rewrite'=>array('slug'=>'samples_weaving/techniques', 'with-front'=>false),
'query_var'=>true
)
);
register_taxonomy('ash_equip_cats', 'ash_equipment',
array( 'labels'=>array( 'name'=>'Equipment Categories',
'singular_name'=>'Equipment Category'),
'public'=>true,
'hierarchical'=>true,
'show_ui'=>true,
'show_in_nav_menus'=>true,
'rewrite'=>array('slug'=>'equipment/category', 'with_front'=>false),
'query_var'=>true
)
);
}
function ASH_addposttypes(){
//good archive url: http://example.com/samples_weaving/
register_post_type('ash_weaving',
array(
'description' => 'Picture, draft and technical details of a weaving sample',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position'=>5,
'rewrite'=>array('slug'=>'samples_weaving', 'with_front'=>false),
'query_var' => true,
'taxonomies'=>array('post_tag','ash_weave_structure','ash_weave_technique'),
'has_archive'=>true,
'supports' => array( 'title',
'editor',
'excerpt',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'),
'labels' => array ( 'name'=>__('Weaving Samples'),
'singular_name'=>__('Weaving Sample')
)
)
);
//bad archive url: http://example.com/archives/samples_spinning/
register_post_type('ash_spinning',
array(
'description' => 'Picture and technical details of a spinning sample',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position'=>5,
'rewrite'=>array('slug'=>'samples_spinning', 'with-front'=>false),
'query_var' => true,
'taxonomies'=>array('post_tag'),
'has_archive'=>true,
'supports' => array( 'title',
'editor',
'excerpt',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'),
'labels' => array ( 'name'=>__('Spinning Samples'),
'singular_name'=>__('Spinning Sample')
)
)
);
//bad archive url: http://example.com/archives/samples_dyeing/
register_post_type('ash_dyeing',
array(
'description' => 'Picture and technical details of a dyeing sample',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position'=>5,
'rewrite'=>array('slug'=>'samples_dyeing','with-front'=>false),
'query_var' => true,
'taxonomies'=>array('post_tag'),
'has_archive'=>true,
'supports' => array( 'title',
'editor',
'excerpt',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes'),
'labels' => array ( 'name'=>__('Dyeing Samples'),
'singular_name'=>__('Dyeing Sample')
)
)
);
//good archive url: http://example.com/equipment/
register_post_type('ash_equipment',
array(
'description' => 'Weaving and spinning equipment that ASH makes available to members',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position'=>5,
'rewrite'=>array('slug'=>'equipment','with_front'=>false),
'query_var' => true,
'taxonomies'=>array('post_tag','ash_equip_cats'),
'has_archive'=>true,
'supports' => array( 'title',
'excerpt',
'thumbnail',
'page-attributes'),
'labels' => array ( 'name'=>__('Equipment'),
'singular_name'=>__('Equipment')
)
)
);
}发布于 2012-02-07 19:17:56
问题是在寄存器函数中,在rewrite中,您必须将with-front更改为with_front。
https://wordpress.stackexchange.com/questions/41531
复制相似问题