0

I'm using a custom post type plugin that returns an uploaded file's attachment ID instead of its url. I've been able to get the image to display using wp_get_attachment_image_src as outlined in the codex here http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src but my problem is getting it to play nicely with the code on the template page used to call the information from the custom post type set up using the [WCK Custom Fields Creator][1] plugin.

Stripping it down to the basics, this is what calls the custom post type info from the template page:

<?php 
    $slideshowplatform = get_post_meta($post->ID, 'slideshowplatform', true);
    foreach($slideshowplatform as $slide) {
        echo '<img src="' . $slide['slide'] . '" />';
    }
?>

I'm having difficulty reconciling this with what the codex provides:

<?php 
    $attachment_id = 8; // attachment ID
    $image_attributes = wp_get_attachment_image_src( $attachment_id ); // returns an array
?>

<img src="<?php echo $image_attributes[0]; ?>">

It seems like something like the following should work, but I'm obviously missing something with the php syntax

<?php 
    $slideshowplatform = get_post_meta($post->ID, 'slideshowplatform', true);
    foreach($slideshowplatform as $slide) {
        $image_attributes = wp_get_attachment_image_src( $slide['slide'] );
        echo '<img src="<?php echo $image_attributes[0]; ?>" />';
    }
 ?>

Any thoughts would be appreciated, thanks.

1

Too many echos. This:

echo '<img src="<?php echo $image_attributes[0]; ?>" />';

Should be this:

echo '<img src="' . $image_attributes[0] . '" />';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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