Piklist 自定义 Post Types 很方便,它们是基于标准的WordPress register_post_type 函数。但你可以用Piklist为Post Types加入一些强大的参数。Piklist 扩展了 register_post_type 函数添加了一些参数特色,详情请查看《Piklist中文手册》中的”自定义Post Types参数”,你可以用标准的register_post_type参数和Piklist扩展的参数,结合使用。
Piklist注册一个post type的步骤:
1.首先,你要决定你的自定义Post Type是写在主题上还是插件上。
- 主题:代码写在functions.php里
- 插件:代码写在主php文件里
注:可查阅入门教程二。
2.创建一个函数,来写Post Type的参数。本教程里,我们命名了一个product_post_type函数。
3.勾住piklist过滤器 piklist_post_types
下面代码,用WordPress 的标准参数和Piklist参数混合创建一个自定义Post Types 注意:post type名的要小写,这是官方标准函数的要求,提个醒。
add_filter('piklist_post_types', 'product_post_type'); function product_post_type($post_types) { $post_types['product'] = array( 'labels' => piklist('post_type_labels', 'Product') ,'taxonomies' => array('post_tag') ,'public' => true ,'rewrite' => array( 'slug' => 'product' ) ,'supports' => array( 'title' ,'author' ,'revisions' ,'editor' ,'thumbnail' ) ,'title' => 'Enter Product Title' ,'edit_columns' => array( 'title' => __('Product Name') ,'author' => __('operator') ) ,'hide_meta_box' => array( 'slug' ,'author' ,'revisions' ,'comments' ,'commentstatus' ) ); return $post_types; }
你在后台管理菜单菜会多出一个Product的Post Type,如下图:
发表评论
要发表评论,您必须先登录。