Pods not displaying the right images when pulling in more than 1 image from related pod
I have a product page, here.
On the bottom right I'm pulling in a brochure from my brochure pod using a multi-select PICK field, using this code:
<?php if($record_brochures) { foreach ($record_brochures as $v) { echo '<h3>Brosjyre</h3><a target="_blank" class="brochurecover" href="' .$v['issuu']. '"><img src="' .$record_brochurecover. '" /></a>'; } } ?>
But when I assign more than one brochure to a product -- say 3 -- it shows the cover image from the first brochure 3 times over. This only happens with the file field. Pulling in any other kind of field seems to work as it should.
Here's the code for how I'm doing all this if you need:
$found_record = false;
global $pods;
$record_slug = pods_url_variable(-1);
$record = new Pod('produkter', $record_slug);
if( !empty( $record->data ) )
{
$found_record = true;
// set our variables
$record_id = $record->get_field('id');
$record_name = $record->get_field('name');
$record_str = $record->get_field('str');
$record_pris = $record->get_field('pris');
$record_shopurl = $record->get_field('shopurl');
$record_produkttype = $record->get_field('produkttype.name');
$record_produktbilde = $record->get_field('produktbilde');
$record_introtekst = $record->get_field('introtekst');
$record_fulltekst = $record->get_field('fulltekst');
$record_bruksanvisning = $record->get_field('bruksanvisning');
$record_ingredienser = $record->get_field('ingredienser');
$record_oppbevaring = $record->get_field('oppbevaring');
$record_faq = $record->get_field('faq');
$record_kontra = $record->get_field('kontra');
$record_brochures = $record->get_field('brochures');
$record_brochurecover = $record->get_field('brochures.cover');
// data cleanup
$record_bio = wpautop( $record_bio );
$record_produktbilde = $record_produktbilde[0]['guid'];
$record_brochurecover = $record_brochurecover[0]['guid'];
}
?>
How do I need to alter my code?
4 Answers
I think I can address the problem but not an exact solution in terms of code. But Ill try to narrow down as far as possibe.
What you do is that you collect the 'guid':s in an array and then output them as with help from a counter increasing parallel with the foreach - as follows:
////////
link to the edited code (btw how do you paste code here?)
////////
Hope that can lead to something in the right direction
edited Oct 8 '10 at 1:42
> link to the edited code (btw how do you paste code here?)
- paste
- select code
- use '101010' code button next to hyperlink & blockquote
Thanks, bjornet. I'm not a developer by any stretch of the imagination, so unfortunately I'd need more exact code than that to make it work within my setup. Your reasoning looks sound, from what I can tell, although this strikes me as something that would be considered a fairly common scenario -- is there not an elegant solution already out there?
Thanks Bjornet and jchristopher for solving this for me.
edited Oct 11 '10 at 4:27


