X

Comment ajouter une vignette à la page d’accueil dans les colonnes de l’Admin Post

Snippets by IsItWP

Vous cherchez un moyen d’ajouter la vignette de l’image vedette à la liste des articles dans l’administration de WordPress ? Bien qu’il existe probablement un plugin pour cela, nous avons créé un extrait de code rapide que vous pouvez utiliser pour ajouter la vignette de l’image vedette dans les colonnes des articles de l’administration.

Instructions:

Tout ce que vous avez à faire est d’ajouter ce code au fichier functions.php de votre thème ou dans un plugin spécifique à votre site:

add_filter('manage_posts_columns', 'posts_columns', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2);

function posts_columns($defaults){
    $defaults['riv_post_thumbs'] = __('Thumbs');
    return $defaults;
}

function posts_custom_columns($column_name, $id){
	if($column_name === 'riv_post_thumbs'){
        echo the_post_thumbnail( 'featured-thumbnail' );
    }
}

Note : Si c’est la première fois que vous ajoutez des extraits de code dans WordPress, veuillez consulter notre guide sur la façon d’ajouter correctement des extraits de code dans WordPress, afin de ne pas casser accidentellement votre site.

Si vous avez aimé cet extrait de code, n’hésitez pas à consulter nos autres articles sur le site comme : 27 meilleurs thèmes WordPress pour les blogs de voyage et comment utiliser Google Optimize sur WordPress.

Commentaires   laisser une réponse

  1. I want a 🔗 in the media library if I don’t have an image

  2. Is there an update on this post. I’ve added the code to my functions file where other custom functions are functioning fine and it doesn’t add anything for extra images within standard or any of the custom post types I’ve created. Any help greatly appreciated. I am running WordPress 5.2.1

  3. When I use this code it brings my products post from woocommerce to my custom post type list.

  4. do i add it to my wp-include/functions.php ? i am using wp4

    1. thanks got it ! love ya !

      1. Cool glad you got it working.

  5. Just what i needed, thanks a lot for great snippet, and the update on how to set thumbnails size just nailed it 🙂

  6. thank you for the snippet. its very helpful as i start to add featured images in all my post. If i like to make this custom column “sortable”, how do i go that? i know its strange to sort image, i just want to see which post do not have image.

  7. Thanks.
    Helped me a lot

  8. Sergey Trushin mai 7, 2013 à 9:59 pm

    Perfect code, thanks!

  9. hi kevin

    could you tell us how to reorder the e.g. 6 columns ???

    thumb – titel – date – user – cont – id
    to:
    id- titel – user – thumb – cont – date

    thanks you

  10. This is working just fine, however the new column is appearing on all custom post type edit screens as well. How would I go about just gettting this to appear on the edit post screens and not the edit CPT screens?

    1. Hi @5f9a29a8407e88a611b5bd004408018e:disqus I know I’m late but hoping this help other with same issue.

      Try this solution
      add_filter( ‘manage_edit-slider_columns’, ‘posts_columns’ ); // slider is the custom post-type you’ve created, feel free to update the post-type to which post-type you only want the custom column to display.

      Hope that helps

  11. Hi,

    I’d like to do that with a custom field value (‘facebook’) would that also be possible?

    Many thanks in advance!

    Cheers,
    Thomas.

    1. you could just get the custom field in the normal way eg:
      $custom_field = get_post_meta($post->ID, ‘facebook’, true);

      then echo the result to the page eg: echo $custom_field;

    2. @wpsnipp:disqus is right but before you can implement or call get_post_meta() function you need to add post_meta first 😉

  12. If post-thumbnails isn’t activated for the theme, only the 1st page/post is listed, with an error in the column.
    To add theme support (functions.php), this is added:
    if ( function_exists( ‘add_theme_support’ ) )add_theme_support( ‘post-thumbnails’ );

    What “IF” checks to see if the theme first supports post-thumbnails?

    1. I agree ill post an updated version of this snippet.

  13. hi, this might seem like a simple question, but where exactly do I place these snippets? functions.php?

    1. Hi onedeep99, yes you should add this snippet to the functions.php of your wordpress theme. I just updated the post to include that little detail as I forgot to mention it.

  14. Thank you for this great snippet. It is very useful to see if there is any thumbs in posts without opening them. Have just a few questions:

    1. Is it possible to get the same feature for the pages too?
    2. Is it possible to display all attached images in a post/page as thumbs instead of just one?
    3. Is it possible to define in which column the they appear in. I get them in the last column in the right of the screen but the default media library displays them in the first column at the left.

    Apreciate your concern 🙂

    1. Hi Zeb,
      1. yes you can ad this to pages as well just add these hooks. above the other hooks.

      add_filter(‘manage_pages_columns’, ‘posts_columns’, 5);
      add_action(‘manage_pages_custom_column’, ‘posts_custom_columns’, 5, 2);

      2. Yes you can reorder the columns Ill post some code asap.
      3. The problem with all attachments is that it may not have enough room for all attachments, Ill see if I can think of another way to display them. 

      1. Thanks alot kevin, 🙂
        If there is any way to specify a number in the snippet for the thumbs to be displayed so that,if needed, a user can change the number OR any other way you might think of would also be great.
        Thanks

        1. I’m not sure I understand can you elaborate a little?

        2. Sorry about not being clear.
          However, I was thinking about a maximum number of how many thumbs to be displayed. For instance, if there is space in the admin, a user can specify max 3 or 4 images to be displayed. Otherwise, “1” could mean only the first or the featured image, even if there is several attachments.
          Another way might be a kind of image rotator using any script.
          I hope I have been helpful 🙂

        3. Ahh ok I see what you mean, Ill look into this a little more could release this as a new snippet.

        4. Great Kevin, thanks 🙂

      2. Is there a way to do it for products?

  15. Thanks a lot for this snippet. Very useful!

    1. Cool glad you like the snippet, don’t forget to follow us on facebook or twitter we post new snippets daily.

  16. hi, I’ve added those snippet but there’s a little problem though. my featured thumbnail appeared in large size (original sizes I think). could you please show me how to resize thumbnail images in admin post columns if possible. thanks.

    1. Hi zarylnaxrie
      ‘featured-thumbnail’ would be a thumbnail size you created however if you replace the code on line nine above with the following.

      echo the_post_thumbnail( array(100,100) );

      Just change the size within the array, the follow page has more details on how post thumbnails function.

      http://codex.wordpress.org/Function_Reference/the_post_thumbnail

      1. Thank you soooooo much!!

  17. Tweets that mention Wordpress Add featured thumbnail to admin post columns – wpsnipp.com Wordpress code snippets for your blog -- Topsy.com février 25, 2011 à 9:36 am

    […] This post was mentioned on Twitter by Y Combinator Newest!, newsery5 and wp_freak, WPSNIPP. WPSNIPP said: #wordpress Add featured thumbnail to admin post columns http://bit.ly/dHuROT #blog please RT 🙂 […]

Ajouter un commentaire

Nous sommes heureux que vous ayez choisi de laisser un commentaire. N'oubliez pas que tous les commentaires sont modérés conformément à notre privacy policy, et que tous les liens sont en nofollow. N'utilisez PAS de mots-clés dans le champ du nom. Engageons une conversation personnelle et constructive.

WordPress Launch Checklist

L'ultime liste de contrôle pour le lancement de WordPress

Nous avons rassemblé tous les éléments essentiels de la liste de contrôle pour le lancement de votre prochain site Web WordPress dans un ebook pratique.
Oui, envoyez-moi le gratuit !