我在函数中有以下代码。php为我提供贴子格式支持和自定义贴子类型“照片”。但我希望帖子格式只适用于“照片”帖子类型,而不适用于内置的“帖子”帖子类型。
add_theme_support( \'post-formats\', array( \'image\', \'chat\', \'video\', \'gallery\' ) );
//custom post type
add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'photos\',
array(
\'labels\' => array(
\'name\' => __( \'Photos\' ),
\'singular_name\' => __( \'Photo\' )
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'photo\'),
\'menu_position\' => 5,
\'taxonomies\' => array(\'genre\'),
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'post-formats\'),
)
);
}
非常感谢您的时间和帮助。
SO网友:WP Themes
try this:
add_action(\'load-post.php\',\'add_post_type_support_stuff\');
add_action(\'load-post-new.php\',\'add_post_type_support_stuff\');
function add_post_type_support_stuff( $post ){
$screen = get_current_screen();
$post_type = $screen->post_type;
if( $post_type == \'photos\' ) {
//add this if you did not add support for the post type when you called register_post_type()
add_post_type_support( \'page\', \'post-formats\' );
//add the post formats
add_theme_support(\'post-formats\',array( \'image\', \'chat\', \'video\', \'gallery\' ));
}
}