Wordpress Post-Thumbnail


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Enable support for post-thumbnails
  2.  
  3. add_theme_support('post-thumbnails');
  4.  
  5. // If we want to ensure that we only call this function if
  6. // the user is working with WP 2.9 or higher,
  7. // let's instead make sure that the function exists first
  8.  
  9. if ( function_exists('add_theme_support') ) {
  10. add_theme_support('post-thumbnails');
  11. }
  12.  
  13. // Insertar dentro de index.php //
  14.  
  15. <?php the_post_thumbnail(); ?>
  16.  
  17.  
  18. // name of the thumbnail, width, height, crop mode
  19. add_image_size( 'post-image', 300, 180, true ); // post image shown in main blog feed
  20. add_image_size( 'featured-image', 652, 245, true ); // large post thumbnail shown in the Featured section
  21. add_image_size( 'slide-image', 900, 300, true ); // really large image for the main front-page slider
  22. add_image_size( 'slide-image-small', 200, 200, true ); // small square image shown in carousel slider in footer
  23. add_image_size( 'latest-post-widget', 80, 80, true ); // really small square shown for latest posts widget
  24. add_image_size( 'related-posts', 180, 180, true );
  25.  
  26. the_post_thumbnail('post-image'); // replace post-image with the name of your thumbnail, as declared above
  27.  
  28.  
  29. if(has_post_thumbnail()) {
  30. the_post_thumbnail('featured-image');
  31. } else {
  32. // show a default image if no thumbnail is set
  33. echo '<img src="path/to/yourimage/jpg" />';
  34. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.