WordPress Pull Featured Image with Permalink and CSS


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

I find myself needing to constantly find new ways to massage the featured image via WordPress themes. This is my starting code. Note: I often use timthumb.


Copy this code and paste it in your HTML
  1. // Add to functions.php theme support for Featured Images if your theme does not already include it.
  2. if (function_exists('add_theme_support')) {
  3. add_theme_support('post-thumbnails');
  4. add_image_size('index-categories', 150, 150, true);
  5. add_image_size('page-single', 575, 200, true);
  6. }
  7.  
  8. Call image using timthumb from a page or post by adding to page.php, single.php, home.php or index.php.
  9.  
  10. <?php if (has_post_thumbnail( $post->ID )): ?>
  11. <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
  12. <img class="featuredImage" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $image[0]; ?>&w=576&h=200&zc=1" alt="<?php the_title(); ?>" />
  13. <?php endif; ?>
  14.  
  15. CSS
  16. Note: image tag has the class .featuredImage. Style as needed:
  17. img.featuredImage{border: 2px solid #ccc;padding: 10px;}

URL: https://hqsecure.com/grab-wordpress-featured-image-url/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.