我三天前就遇到了这个问题,然后我在wp.tutsplus.com. 为了更好地适应您的问题,我交换了自己的代码,但这就是我在看完本系列之后得到的结果。此外,请记住,这是未经测试的。
// sets custom post type
function my_custom_post_type() {
register_post_type(\'Projects\', array(
\'label\' => \'Projects\',\'description\' => \'\',
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => false,
\'query_var\' => true,
\'has_archive\' => true,
\'supports\' => array(\'title\',\'editor\',\'excerpt\',\'trackbacks\',\'custom-fields\',\'comments\',\'revisions\',\'thumbnail\',\'author\',\'page-attributes\'),
\'taxonomies\' => array(\'category\',\'post_tag\'),
// there are a lot more available arguments, but the above is plenty for now
));
}
add_action(\'init\', \'my_custom_post_type\');
// rewrites custom post type name
global $wp_rewrite;
$projects_structure = \'/projects/%year%/%monthnum%/%day%/%projects%/\';
$wp_rewrite->add_rewrite_tag("%projects%", \'([^/]+)\', "project=");
$wp_rewrite->add_permastruct(\'projects\', $projects_structure, false);
理论上,您可以交换存储在
$projects_structure
变量,这里的内容就是我最终使用的内容。
祝你好运,一如既往-一定要回来让我们知道结果如何!:)