Wordpress-Timthumb-alternative icon indicating copy to clipboard operation
Wordpress-Timthumb-alternative copied to clipboard

Creating A Function to get Featured image

Open thepatent opened this issue 10 years ago • 1 comments

Hi!

I know php and developing Wordpress themes fairly well ( but still consider myself a n00b) and am having trouble creating a function to use with this alternative for featured images. I am trying to pass the wp_get_attachment_image_src( ) call using this :

function tpp_custom_img( $thumb_size, $image_width, $image_height ) {

global $post;

$params = array( 'width' => $image_width, 'height' => $image_height );

$url = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID, '' ), $thumb_size ); $custom_img_src = matthewruddy_image_resize( $url[0], $params );

return $custom_img_src;

}

But it is not working. please help.

thepatent avatar Jan 02 '15 04:01 thepatent

Here is my contribution - though it may be a few years late for the OP - maybe someone else can find it helpful;


<?php if (has_post_thumbnail ()) {

// get the src of the large size featured image
$featimg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' ); 
$url = $featimg [0];
$width = 310;                                                                  // Optional. Defaults to '150'
$height = 160;                                                                 // Optional. Defaults to '150'
$crop = true;                                                                  // Optional. Defaults to 'true'
$retina = false;                                                               // Optional. Defaults to 'false'

$image = matthewruddy_image_resize( $url, $width, $height, $crop, $retina );
// output image resized with timthumb 
?>
<div class="thumbnail">
<a href="<?php the_permalink(); ?>"><img src="<?php echo $image['url']; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?> - Click to view">
<?php } else { ?>
<div class="nothumbnail"><p>no image </p></div>
<?php }  ?>


solaceten avatar Jun 24 '20 01:06 solaceten