将帖子类型添加到主题

将后期格式添加到 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')
    )
  );
}