Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating A Function to get Featured image #22

Open
thepatent opened this issue Jan 2, 2015 · 1 comment
Open

Creating A Function to get Featured image #22

thepatent opened this issue Jan 2, 2015 · 1 comment

Comments

@thepatent
Copy link

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.

@solaceten
Copy link

solaceten commented Jun 24, 2020

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 }  ?>


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants