Post by squtternutbosh » Thu Mar 15, 2012 7:28 pm

PHP 101 time:

Have the following statement:

Code: Select all

<?php foreach ($images as $image) { ?>
				<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">Click here for large image</a> 
		<?php } ?>
Displays this:
image1.jpg

image1.jpg (15.86 KiB) Viewed 2167 times

Need to display only the first "Click here for large image" as this links to a fancybox pop-up that can then be scrolled left or right to reveal more additional images (would be satisified with that solution) but to achieve this the code still needs to run just not echo the text link multiple times.

FYI: the additional images change the main 'zoomable' image when clicked hence the need for this extra link.

Guessing this is pretty simple PHP but am struggling to find an answer i can understand elsewhere so hope someone can help.

Version 1.5.1.2 - link: http://oceanlifestyle.com/shop/Gifts/Na ... Gone-signs
Last edited by squtternutbosh on Tue Nov 13, 2012 1:22 am, edited 1 time in total.

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm

Post by rph » Fri Mar 16, 2012 5:32 am

Code: Select all

<?php if (isset($images[0]['popup'])) { ?>
  <a href="<?php echo $images[0]['popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">Click here for large image</a>
<?php } ?>
Last edited by rph on Fri Mar 16, 2012 9:39 pm, edited 1 time in total.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by squtternutbosh » Fri Mar 16, 2012 4:36 pm

Thanks so much for your help, unfortunately i get this error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/a5877638/public_html/shop/catalog/view/theme/default/template/product/product.tpl on line 32

Here is the full code for the additional images section as it was:

Code: Select all

<?php } ?>
      <?php if ($images) { ?>
      <div class="image-additional">
        <?php foreach ($images as $image) { ?>
        
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo $image['thumb']; ?>' ">
		<img src="<?php echo $image['thumb']; ?>" width="74" height="74">
		</a>
		<?php } ?>
		<br>
		<?php foreach ($images as $image) { ?>
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">Click here for large image</a> 
		<?php } ?>
		        
      </div>
      <?php } ?>
    </div>
    <?php } ?>
And with the new suggested code below: maybe i just put it in the wrong place?

Code: Select all

<?php } ?>
      <?php if ($images) { ?>
      <div class="image-additional">
        <?php foreach ($images as $image) { ?>
        
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo $image['thumb']; ?>' ">
		<img src="<?php echo $image['thumb']; ?>" width="74" height="74">
		</a>
		<?php } ?>
		<br>
		
		
		    <?php if (isset($images[0]['popup'])) { ?>
      <a href="<?php echo $images[0]'popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">Click here for large image</a>
    <?php } ?>
		
	
		
	        
      </div>
      <?php } ?>
    </div>
    <?php } ?>

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm

Post by rph » Fri Mar 16, 2012 9:39 pm

Missed a bracket is all. Should work now.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by squtternutbosh » Fri Mar 16, 2012 11:00 pm

Nearly there but not quite, now i only get the one "click for larger image" (as required)

but only one image is loaded to the fancy box - currently it loads all three (so you can scroll left or right to see additional ones within the fancybox viewer as standard)

but also displays "click here for larger image" multiple times for each additional image (see 1st image on original post).

All i can think is maybe there's a way of setting style="display:none" on the recurring "click here' "s but so far each way i do it achieves the same as your attempt...

Is a shame cos it's taken me months to make the additional images zoomable as my php knowledge is pretty poor!

Do appreciate you taking the time to help though Ryan, thanks :)

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm

Post by squtternutbosh » Fri Mar 23, 2012 1:11 am

Didn't think this would be quite so tricky...

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm

Post by squtternutbosh » Fri Mar 30, 2012 4:59 pm

Any other suggestions?

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm

Post by squtternutbosh » Tue Nov 13, 2012 1:17 am

Ha ha! Finally figured it out, only took 8 months!!

Code: Select all

<?php if ($images) { ?>
      <div class="image-additional">
        <?php foreach ($images as $image) { ?>
        
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="cloud-zoom-gallery" rel="useZoom: 'zoom1', smallImage: '<?php echo $image['thumb']; ?>' ">
		<img src="<?php echo $image['thumb']; ?>" width="74" height="74">
		</a>
		<?php } ?>
		<br>
		
		<?php $counter = 0; { ?>
		<?php foreach ($images as $image) { 
		if ($counter==0) { ?>
		
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">Click here to view large images</a> 
		
		
		
		<?php } else { ?>
	
		<a href="<?php echo $image['popup']; ?>" title="<?php echo $heading_title; ?>" class="fancybox" rel="fancybox">  </a> 
	
		<?php } $counter++ ; } ?>
	
		<?php } ?>
		
	      
      </div>
	  <?php } ?>
As you can see code looks pretty ropey but it actually works, hope this helps anyone stuck with a similar problem - notice the repeated lines are there as blank spaces ' ' - this is probably not the soundest way to achieve this but am content and just happy to have worked it out through trial and error.

link here to the same page as the original post showing it working:
http://oceanlifestyle.com/shop/Gone-signs

New member

Posts

Joined
Tue Nov 01, 2011 10:11 pm
Who is online

Users browsing this forum: No registered users and 26 guests