Comment ajouter la prise en charge des vignettes pour les types de publication personnalisés?
3 réponses
- votes
-
- 2012-07-06
Par défaut,tous les articlespersonnalisésprennenten charge letitreet l'éditeur,si vous voulezplus de choses comme des commentaires,des vignetteset des révisions,vous devez l'ajoutermanuellement dans l'argument support .
En savoirplus sur l'enregistrement de votretype demessagepersonnalisé ici ,vouspouvez égalementtrouver la section sur l'assistance pour voir ce que vouspouvez ajouter.
Voici unexemple oùenregistrer une vignettepour lemessagepersonnalisé "Livres"et ilprenden charge:
'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'
function codex_custom_init() { $labels = array( 'name' => _x('Books', 'post type general name'), 'singular_name' => _x('Book', 'post type singular name'), 'add_new' => _x('Add New', 'book'), 'add_new_item' => __('Add New Book'), 'edit_item' => __('Edit Book'), 'new_item' => __('New Book'), 'all_items' => __('All Books'), 'view_item' => __('View Book'), 'search_items' => __('Search Books'), 'not_found' => __('No books found'), 'not_found_in_trash' => __('No books found in Trash'), 'parent_item_colon' => '', 'menu_name' => __('Books') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ); register_post_type('book',$args); } add_action( 'init', 'codex_custom_init' );
By default all custom post adds support for Title and editor, if you want more stuff like comments, thumbnail and revisions you have to add it manually in the support argument.
Read more about how to register your custom post type here, you can also find the section about support to see what you can add.
Here is an example wehere to register thumbnail for the custom post "Books" and it hav support for:
'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'
function codex_custom_init() { $labels = array( 'name' => _x('Books', 'post type general name'), 'singular_name' => _x('Book', 'post type singular name'), 'add_new' => _x('Add New', 'book'), 'add_new_item' => __('Add New Book'), 'edit_item' => __('Edit Book'), 'new_item' => __('New Book'), 'all_items' => __('All Books'), 'view_item' => __('View Book'), 'search_items' => __('Search Books'), 'not_found' => __('No books found'), 'not_found_in_trash' => __('No books found in Trash'), 'parent_item_colon' => '', 'menu_name' => __('Books') ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) ); register_post_type('book',$args); } add_action( 'init', 'codex_custom_init' );
-
J'utilisaispost-vignette au lieu de vignette.Cela a du sensmaintenant.post-vignette ajoute une vignettepour lemessagemaispour letype depublicationpersonnalisé,ilfaut une vignetteI was using post-thumbnail instead of thumbnail . It makes sense now . post-thumbnail adds thumbnail for the post but for custom post type one needs thumbnail
- 0
- 2015-01-27
- Akash Kumar Sharma
-
J'ai une «miniature» dansmontableau «prenden charge»maisje nepeuxpasenregistrer l'image sélectionnée dansmonmessagepersonnalisé.I have 'thumbnail' in my 'supports' array but I cannot save featured image in my custom post.
- 2
- 2016-06-27
- esmitex
-
- 2016-11-04
Pour les articlespersonnalisés,vous devez d'abord activer lapriseen charge desminiatures:
add_theme_support( 'post-thumbnails' ); function theme_setup() { register_post_type( 'yourposttype', array( ..., 'supports' => array('title', ...,'thumbnail'), )); } add_action( 'after_setup_theme', 'theme_setup' );
For custom posts, you first have to enable support for thumbnails:
add_theme_support( 'post-thumbnails' ); function theme_setup() { register_post_type( 'yourposttype', array( ..., 'supports' => array('title', ...,'thumbnail'), )); } add_action( 'after_setup_theme', 'theme_setup' );
-
Cela aparfaitementfonctionnépourmoi,maispouvez-vousexpliquerpourquoi "add_theme_support ('post-thumbnails');"estnécessaire d'ajouter?Worked for me perfectly but can you please explain why "add_theme_support( 'post-thumbnails' );" is necessary to add?
- 0
- 2020-01-03
- Adi
-
- 2018-09-25
Vouspouvez également utiliser
add_post_type_support()
pour ajouter une seulefonctionnalité,si vousne souhaitezpas réécrire les optionspar défautsupports
lors de l'enregistrement de votretype depublicationpersonnalisé:add_post_type_support( 'product', 'thumbnail' );
You can also use
add_post_type_support()
to add a single feature, if you don't want to rewrite the defaultsupports
options when registering your custom post type:add_post_type_support( 'product', 'thumbnail' );
Lapriseen charge des vignettesfonctionnepour lapublication,maisj'ai un autretype depublication appeléproduitet celane fonctionnepaspour cela.J'essaye:
add_theme_support( 'post-thumbnails', array( 'post', 'product' ) );
J'utilise également leplugin de vignettes demessagesmultiples.