自定义帖子不显示特色图片

时间:2013-05-07 作者:NielsPilon

我可能遗漏了一些东西,但我的自定义帖子类型在创建帖子时没有显示特色图像输入字段。我的功能中已经注册了特色图像。php,它确实会出现在页面和常规帖子中。但不是在我的自定义帖子类型。

这是我用来启用特色图像的代码

add_theme_support(\'post-thumbnails\');
以及注册自定义帖子类型的代码

add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'vacature\',
    array( \'labels\' => array(
            \'name\' => __( \'Vacatures\' ),
            \'singular_name\' => __( \'Vacature\' ),
        ),
    \'public\' => true,
    \'has_archive\' => true,
    \'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'comments\' ),
    )
    );
}

2 个回复
SO网友:Pramod Pandey

更改此行

add_theme_support( \'post-thumbnails\');

add_theme_support( \'post-thumbnails\', array(\'post\', \'page\',\'vacature\'));
我想这对你有帮助。

SO网友:Adi

嗯,我使用了一些不同类型的代码,可以定制帖子,但它工作得很好。其中保存标签、类别、自然图像。这里是代码,希望能对您有所帮助。

function my_custom_post_faq() {
    $labels = array(
        \'name\'               => _x( \'Slides\', \'post type general name\' ),
        \'singular_name\'      => _x( \'Slides\', \'post type singular name\' ),
        \'add_new\'            => _x( \'Add New\', \'Slides\' ),
        \'add_new_item\'       => __( \'Add New Slide\' ),
        \'edit_item\'          => __( \'Edit Slide\' ),
        \'new_item\'           => __( \'New Slide\' ),
        \'all_items\'          => __( \'All Slides\' ),
        \'view_item\'          => __( \'View Slides\' ),
        \'search_items\'       => __( \'Search Slides\' ),
        \'not_found\'          => __( \'No Slide found\' ),
        \'not_found_in_trash\' => __( \'No Sliode found in the Trash\' ), 
        \'parent_item_colon\'  => \'\',
        \'menu_name\'          => \'Slide\'
    );
    $args = array(
        \'labels\'        => $labels,
        \'description\'   => \'Holds our Slides and Slide specific data\',
        \'public\'        => true,
        \'menu_position\' => 5,
        \'supports\'      => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\', \'comments\' ),
        \'has_archive\'   => true,
    );
    register_post_type( \'faq\', $args ); 
}
add_action( \'init\', \'my_custom_post_faq\' );


/*----------- For tags -------------*/

function my_taxonomies_faq() {
    $args = array();
    register_taxonomy( \'faq_category\', \'faq\', $args );
}

add_action( \'init\', \'my_taxonomies_faq\', 0 );




/*----------- For categories -------------*/

function my_taxonomies_faq_cat() {
    $labels = array(
        \'name\'              => _x( \'FAQ Categories\', \'taxonomy general name\' ),
        \'singular_name\'     => _x( \'FAQ Category\', \'taxonomy singular name\' ),
        \'search_items\'      => __( \'Search FAQ Categories\' ),
        \'all_items\'         => __( \'All FAQ Categories\' ),
        \'parent_item\'       => __( \'Parent FAQ Category\' ),
        \'parent_item_colon\' => __( \'Parent FAQ Category:\' ),
        \'edit_item\'         => __( \'Edit FAQ Category\' ), 
        \'update_item\'       => __( \'Update FAQ Category\' ),
        \'add_new_item\'      => __( \'Add New FAQ Category\' ),
        \'new_item_name\'     => __( \'New FAQ Category\' ),
        \'menu_name\'         => __( \'FAQ Categories\' ),
    );
    $args = array(
        \'labels\' => $labels,
        \'hierarchical\' => true,
    );
    register_taxonomy( \'faq_category\', \'faq\', $args );
}
add_action( \'init\', \'my_taxonomies_faq_cat\', 0 );

结束

相关推荐