/ Published in: PHP
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Add to functions.php theme support for Featured Images if your theme does not already include it. if (function_exists('add_theme_support')) { add_theme_support('post-thumbnails'); add_image_size('index-categories', 150, 150, true); add_image_size('page-single', 575, 200, true); } Call image using timthumb from a page or post by adding to page.php, single.php, home.php or index.php. <?php if (has_post_thumbnail( $post->ID )): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?> <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(); ?>" /> <?php endif; ?> CSS Note: image tag has the class .featuredImage. Style as needed: img.featuredImage{border: 2px solid #ccc;padding: 10px;}
URL: https://hqsecure.com/grab-wordpress-featured-image-url/