wordpress自定义文章类型功能添加
我们在做wordpress企业站的时候常常需要增加自定义文章类型
类似于产品中心,案例中心,新闻资讯
不同分类需要调用不同的模板,所以我们可以通过自定义文章类型来定义
下面以添加产品中心来举例:
1.在主题函数functions.php中添加一下代码
add_action( 'init', 'create_product_post_types' );
function create_product_post_types() {
register_post_type( 'product',
array(
'labels' => array(
'name' => __( '产品中心' ),
'singular_name' => __( '产品中心' ),
'add_new' => __( '添加' ),
'add_new_item' => __( '创建' ),
//'edit' => __( 'Edit' ),
// 'edit_item' => __( 'Edit Super Duper' ),
'new_item' => __( '所有产品' ),
//'view' => __( 'View Super Duper' ),
//'view_item' => __( 'View Super Duper' ),
'search_items' => __( '搜索' ),
'not_found' => __( '没有搜索到' ),
'not_found_in_trash' => __( '没有搜索到' ),
//'parent' => __( 'Parent Super Duper' ),
),
'public' => true,
//'rewrite' => array('slug' => 'job'),
//'menu_position' => 15,
'supports' => array( 'title', 'editor','thumbnail','excerpt', 'author' ),
//'taxonomies' => array( '' ),
//'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
'has_archive' => true,
)
);
}
2.增加wordpress自定义文章的分类功能
add_action( 'init', 'create_product_taxonomies', 0 );
function create_product_taxonomies() {
register_taxonomy(
'product_genre',
'product',
array(
'labels' => array(
'name' => '产品分类',
'add_new_item' => '添加分类',
'new_item_name' => "新分类"
),
'show_ui' => true,
'show_tagcloud' => false,
'hierarchical' => true
)
);
}
展示效果;

下篇文章给大家介绍wordpress自定义类型文章的调用。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















