將帖子型別新增到主題
將後期格式新增到 post_typepage
add_post_type_support( 'page', 'post-formats' );
下一個示例註冊自定義帖子型別’my_custom_post_type’,並新增 Post Formats。
註冊自定義帖子型別’my_custom_post_type'
add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
register_post_type( 'my_custom_post_type',
array(
'labels' => array( 'name' => __( 'Products' ) ),
'public' => true
)
);
}
將後期格式新增到 post_type’my_custom_post_type'
add_post_type_support( 'my_custom_post_type', 'post-formats' );
或者在函式 register_post_type()
中,在’supports’引數陣列中新增’post-formats’。下一個例子相當於上面的例子。
使用’supports’引數註冊自定義帖子型別’my_custom_post_type'
add_action( 'init', 'create_my_post_type' );
function create_my_post_type() {
register_post_type( 'my_custom_post_type',
array(
'labels' => array( 'name' => __( 'Products' ) ),
'public' => true,
'supports' => array('title', 'editor', 'post-formats')
)
);
}