我正在编写一个自定义帖子类型作为插件,并试图找出如何在插件文档/模板中启用帖子缩略图,而不是在函数中启用它。php。我尝试在自定义贴子插件中添加下面的代码。php和它似乎不起作用。我仍然需要在函数中编写代码。php为我的自定义帖子启用帖子缩略图
/ * ADD THUMBNAIL FOR POST
* ------------------------------------------------------------------------ */
add_theme_support( \'post-thumbnails\', array( \'post\', \'custom-post\' ) );
下面的示例代码
<?php
/*
Plugin Name: Example Custom Post Plugin
Description: Example post plugin for News and Press custom post
*/
?>
<?php
/* ------------------------------------------------------------------------ *
* EXAMPLE CUSTOM POST
------------------------------------------------------------------------ */
function example () {
// Set UI labels for Custom Post Type
$labels = array(
\'name\' => _x( \'Example\', \'Post Type General Name\', \'twentythirteen\' ),
\'singular_name\' => _x( \'Example\', \'Post Type Singular Name\', \'twentythirteen\' ),
\'menu_name\' => __( \'Example\', \'twentythirteen\' ),
\'parent_item_colon\' => __( \'Parent Example\', \'twentythirteen\' ),
\'all_items\' => __( \'All Post\', \'twentythirteen\' ),
\'view_item\' => __( \'View Post\', \'twentythirteen\' ),
\'add_new_item\' => __( \'Add New Post\', \'twentythirteen\' ),
\'add_new\' => __( \'Add Post\', \'twentythirteen\' ),
\'edit_item\' => __( \'Edit Post\', \'twentythirteen\' ),
\'update_item\' => __( \'Update Post\', \'twentythirteen\' ),
\'search_items\' => __( \'Search Post\', \'twentythirteen\' ),
\'not_found\' => __( \'Not Found\', \'twentythirteen\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'twentythirteen\' ),
);
// Set other options for Custom Post Type
$args = array(
\'label\' => __( \'Example\', \'twentythirteen\' ),
\'description\' => __( \'Example\', \'twentythirteen\' ),
\'labels\' => $labels,
// Features this CPT supports in Post Editor
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
\'taxonomies\' => array(\'category\', \'post_tag\'),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 4,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'capability_type\' => \'page\',
);
// Registering your Custom Post Type
register_post_type( \'example\', $args );
}
/* Hook into the \'init\' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( \'init\', \'example\', \'example\', 1 );
add_action( \'after_setup_theme\', \'example_featured_image\');
function example_featured_image() {
add_theme_support( \'post-thumbnails\', array( \'post\', \'page\', \'production_firm\', \'example\' ) );
}