• Resolved KS Web Designer

    (@ks-webdesignercom)


    Hey, so I have been wrapping my brain around this for a few hours and I must be missing something really obvious, so I was wondering if someone could help out.

    I have created a ‘Banner’ content type which has various custom fields to specify text and image for each banner. Using anoter custom field on a page I can relate multiple instances of banners to my page, and want to pull through the custom fields from those banners.

    Reading through the documentation I have got as far as pulling all the information through and spitting it out as structured HTML – EXCEPT for the image. All I can seem to get back is the attachment ID. I have dont similar things in the past using the wp_get_attachment_image_src() call – but this doesn’t seem to work within the foreach statement.

    My code:

    $banners = get_custom_field('relatedBanners:to_array', 'get_post');
    	foreach ($banners as $b) {
    		//print_r($b); // this will show you EVERYTHING that's available in that post
    		$bannerTitle = $b['post_title'];
    		$bannerDescription = $b['bannerDescription'];
    		$buttonText = $b['buttonText'];
    		$bannerLink = $b['bannerLink'];
    		$bannerImg = $b['bannerImage'];
    
    		$banner_html[] = '<div class="indvdlBanner"><div class="overlay"><div class="title">' . $bannerTitle . '</div><div class="description">' . $bannerDescription . '</div><a href="' . $bannerLink . '" class="button" title="' . $bannerTitle . '">' . $buttonText . '</a></div></div><img src="' . $bannerImg . '" />';
    	}

    <?php echo implode("\n", $banner_html); ?>

    Can anyone help me convert the bannerImg variable from just the image ID to the source URL of the image?

    Thank you

    http://wordpress.org/plugins/custom-content-type-manager/

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Converting related attachment ID to image source’ is closed to new replies.