0

I am wanting to use the post thumbnail with the nivo slider and for it to generate the image from a custom image size (already declared in my functions file)

I wrote this (for generating the images)

<img src="<?php the_post_thumbnail(); ?>" data-thumb=""<?php the_post_thumbnail('sliderimage')> title="" />

It doesnt seem to load the images, however if i take away the image tags etc it works.

Can the above be achieved this way so that it auto generates the thumbnails and loads the images?

1 Answer 1

0

the_post_thumbnail() displays the featured image. get_the_post_thumbnail() retrieves it for use in code. Try something like this:

<?php
$featured_image = get_the_post_thumbnail( get_the_ID() );
$fi_src = $featured_image['src'];
$slider = get_the_post_thumbnail( get_the_ID(), 'sliderimage' );
$s_src = $slider['src'];
?>
<img src="<?php echo $fi_src; ?>" data-thumb=""<?php echo $s_src; ?> title="" />
8
  • Hi Pat i tried this at it came up with a fatal error: undefined function get_post_thumbnail() Commented Jan 18, 2014 at 22:06
  • i posted the featured image bit into my functions and the other bit into my sidebar file Commented Jan 18, 2014 at 22:07
  • Whoops, it's get_the_post_thumbnail(), not get_post_thumbnail(). I've updated my answer.
    – Pat J
    Commented Jan 18, 2014 at 22:20
  • hi pat, its coming up with a forbidden error now... is it the case i cant hardcode this in wordpress unlike the plugin you can prebuy? Commented Jan 18, 2014 at 22:25
  • im assuming i add this whole code to my sidebar, as adding the first part to the functions didnt pull the image :S Commented Jan 18, 2014 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.