Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Cristian Antohe

    (@sareiodata)

    You’re right, we’re only storing the Image ID so we can use WordPress’s internal image resizing functions.

    So instead of

    <?php echo $content['image1']; ?>

    Do something like:

    $image = $content['image1'];
    $attachment_image = wp_get_attachment_image_src( $image, 'full' );
    $src = $attachment_image[0];
    
    if( !empty( $src ) )
      echo '<img src="'.$src.'"/>';

    Hope this works out for you!

    Notice wp_get_attachment_image_src( $image, ‘full’ ). In the second parameter you can put any thumbnail image size defined in your WordPress installation.

    Hi, I have the same problem but the solution above didn’t help me. Currently, my code is like this (based on the video tutorial by sareiodata):

    echo '<img src="' .$subproduct['product-img'] . '" class="alignleft" />';

    So how can I get the image to show, not the numbers?

    Thanks.

    Plugin Author Cristian Antohe

    (@sareiodata)

    Hi Inv77,

    The above solution really should have worked:

    $image = $content['image1'];
    $attachment_image = wp_get_attachment_image_src( $image, 'full' );
    $src = $attachment_image[0];
    
    if( !empty( $src ) )
      echo '<img src="'.$src.'"/>';

    Do you get any type of php errors? Try and do a var_dump($attachment_image); and list what you get here.

    Hi and thanks for the answer. I guess I’m a little confused where this code should go exactly. Do I just replace:

    echo '<img src="' .$subproduct['product-img'] . '" class="alignleft" />';

    With your code?

    Plugin Author Cristian Antohe

    (@sareiodata)

    Yes 🙂

    The reason for this is that we now store the ID of the attachment, not the link to the image. So you need to do an extra query to get the actual image from it’s ID in the database.

    That didn’t work. Should I put it in context? This is how the whole thing looks (without your code):

    <?php
    
    	$productdetails = get_post_meta($post->ID, 'productdetails', true);
    		echo '<ul>';
    		foreach($productdetails as $subproduct){
    			echo '<li>';
    			echo '<img src="' .$subproduct['product-img'] . '" class="alignleft" />';
    			echo '<h3>' .$subproduct['product-title']. '</h3>';
    			echo '<p>' .$subproduct['product-description']. '</p>';
    			echo '</li>';
    		}
    		echo '</ul>';
    
    		?>

    So when I tried replacing the line with your code no output was there at all in the source. Please help! Thanks.

    Plugin Author Cristian Antohe

    (@sareiodata)

    Try this :

    $productdetails = get_post_meta($post->ID, 'productdetails', true);
    		echo '<ul>';
    		foreach($productdetails as $subproduct){
    			echo '<li>';
    
    			$image = $subproduct['product-img'];
    			$attachment_image = wp_get_attachment_image_src( $image, 'full' );
    			$src = $attachment_image[0];
    
    			if( !empty( $src ) )
    			  echo '<img src="'.$src.'" class="alignleft"/>';
    
    			echo '<h3>' .$subproduct['product-title']. '</h3>';
    			echo '<p>' .$subproduct['product-description']. '</p>';
    			echo '</li>';
    		}
    		echo '</ul>';

    I replaced $content[‘image1’] with your own $subproduct[‘product-img’]. If it doesn’t work try and activate debug mode in WordPress (http://codex.wordpress.org/Debugging_in_WordPress) and let me know what errors come up.

    That worked! Thanks a lot and thanks for the plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Images show as a number.’ is closed to new replies.