WordPress.org

Ready to get started?Download WordPress

Forums

Custom Fields Creator
Image DIsplay (9 posts)

  1. gowrann
    Member
    Posted 2 years ago #

    Hi,

    Great plugin - but can't get images to display - I have watched the tutorial but images are not displaying. My code is:

    <div id="quotes"><h3>Quotes</h3>
    			<?php $quotes = get_post_meta( $post->ID, 'quotes', true );
    			foreach( $quotes as $quote){
    			   	echo '<div>';
    				echo '<img src="' . $quote['quotes_pic'] . '" class="alignleft" />';
    				echo '<p>' . $quote['quotes_text'] . '</p>';
    				echo '<p><strong>' . $quote['quotes_author'] . '</strong></p>';
    				echo '</div>';
    }
    
    			?>

    but that brings in the attachment ID as the path - what is the right way to get the path and also display a certain size.

    Thanks

    http://wordpress.org/extend/plugins/custom-fields-creator/

  2. madalin.ungureanu
    Member
    Plugin Contributor

    Posted 2 years ago #

    Hello!

    In version 1.0.2 we changed the upload field from storing the url to the file into storing the attachment ID for the file.

    So now you can use functions like wp_get_attachment_image, wp_get_attachment_image_src or wp_get_attachment_url depending on the desired functionality

  3. gowrann
    Member
    Posted 2 years ago #

    hi is it possible you can state the code/syntax for the function to display the image - wp_get_attachment_image, wp_get_attachment_image_src or wp_get_attachment_url to actually display the link (sorry.... just starting out in php)

    I received your reply via email but is not listed here in WordPress support

    Thanks

  4. madalin.ungureanu
    Member
    Plugin Contributor

    Posted 2 years ago #

    In case you didn't get the codex links from my previous answer here they are again:
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_url

    They provide a pretty detailed description of the functions and also usage examples. Hope it helps!

  5. Pedromrferreira
    Member
    Posted 1 year ago #

    Hi, love your plugin.
    Cant put images working, who do I set the code for wp_get_attachment_image on version 1.0.3? can you explane the code?
    Thanks

  6. brendanrandall
    Member
    Posted 1 year ago #

    I'm having the same issue. The plugin is great indeed but could you give a full code example of getting the image with version 1.0.3 upwards. If we take a simple use case:

    foreach($items as $item){
    echo '<img src="'.$item['item_pic'].'" />';
    }

    What would be the code equivalent in the newer version?

    Many thanks.

  7. brendanrandall
    Member
    Posted 1 year ago #

    Hey Pedromrferreira,

    I've been looking into this and i have a solution for you. Please see below. Hopefully this will help others out since the change in the plugin's way of accessing images. The exampel below is something i've worked up which loops through all images in a repeater and outputs both a thumbnail and full size image so you can pick from what you want. If you have other sizes specified in Worpdress you can just replace 'full' with your named image size:

    <?php

    $clientimages = get_post_meta( $post->ID, 'clients', true );

    foreach($clientimages as $clientimage){ // For each loop for
    $thumbnail = wp_get_attachment_image_src( $clientimage['clientimage'] );
    $full = wp_get_attachment_image_src( $clientimage['clientimage'],'full' );
    echo '<img src="' . $thumbnail[0] . '" />';
    echo '<img src="' . $full[0] . '" />';
    }

    ?>

  8. Pedromrferreira
    Member
    Posted 1 year ago #

    OK, got it:

    <?php
    $actividades = get_post_meta( $post->ID, 'actividades', true );
    echo '<ul class="content-act">';
    foreach( $actividades as $actividade){
    echo '
    
    <li>';
    echo '<h2>' . $actividade['titulo'] . '</h2>';
    $attachment_image = wp_get_attachment_image_src($actividade['imagem'], 'full');
    
    echo '<img src="'. $attachment_image[0].'" width="<'. $attachment_image[1] .'" height="'. $attachment_image[2] .'"/>';
    echo '<p>' . $actividade['descricao'] . '</p>';
    echo '</li>
    ';
    }
    echo '';
    
    ?>
  9. Tukaram Kalane
    Member
    Posted 1 year ago #

    Use This: Had same problem... It worked for me...

    $result = wp_get_attachment_image_src($addbooks['book-image']);
    $url = $result[0];
    echo '<img src="'. $url.'" >';

    where,
    '$addbooks' : name of metabox.
    'book-image' : name of image field.
    It will show image in thumbnail for showing full image. USe:
    $result = wp_get_attachment_image_src($addbooks['book-image'],'full');

    Hope it will help you...
    Happy Coding...!!! -TK

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic