在使用code创建post type 和 taxonomy 之前,希望你知道怎么一个一个创建post type,这是基础。
在function.php中引入下载的两个文件,文件放入themes/主题/includes目录下;
include_once(“includes/class-post-type.php”);
include_once(“includes/class-taxonomy.php”);
之后就可以用code创建post type和taxonomy了;
Custom_Post_Type_Post:创建一个post类型type;
Custom_Post_Type_Page:创建一个Page类型type
new Custom_Taxonomy:创建一个taxonomy,$post_types = array(‘$post_type’)代表是为$post_type创建的分类。
必填四个属性,看下面code第一行,默认has_archive被设置成了false,需要has_archive可以设置为true,
1 2 3 4 5 |
//new Custom_Post_Type_Post($post_type = 'news', $plural = 'News', $single = 'News', $description = ''); //默认创建一个post格式 //new Custom_Post_Type_Post($post_type = 'product', $plural = 'Product', $single = 'Product', $description = '', $has_archive = true); //new Custom_Post_Type_Page($post_type = 'custom_page', $plural = 'Custom Page', $single = 'Custom Page', $description = '', $rewrite = 'custom');//默认创建一个page格式 //new Custom_Taxonomy($taxonomy = 'product-category', $plural = 'Categories', $single = 'Category', $post_types = array('product'));//默认创建一个taxonomy |
当然了,这里对一些参数都简写了,如果有需要,请自行更改,对后台要求不高的,已经够用了。
1 2 3 4 5 6 7 |
$labels = array( 'name' => $this->plural, 'singular_name' => $this->single, 'name_admin_bar' => $this->single, 'add_new' => _x( '新增', '' ).$this->single, 'add_new_item' => '新增 '.$this->single, ); |