Forums / General Questions / Limit additional images listed?

Limit additional images listed?

Views: 3,126

Results 1 to 20 of 34
26 Apr 2012, 4:02 PM
#1
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Limit additional images listed?

can anyone explain if there is a way to limit the number of additional images shown?

My supplier provides up to 10 but I only want to display a maximum of 3? is there any way to only get it to display the first 3 found?

Thanks in advance.

Phil

Phil Rogers
A problem shared is a problem solved.

26 Apr 2012, 8:33 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Limit additional images listed?

You could copy /includes/modules/additional_images.php into /includes/modules/YOUR_TEMPLATE/additional_images.php and edit the following section (from the 1.5.0 version):

 // Check for additional matching images
  $file_extension = $products_image_extension;
  $products_image_match_array = array();
  $files_found = 0;  /* Add this */
  if ($dir = @dir($products_image_directory)) {
    while ($file = $dir->read() && $files_found < 3) {  /* Change this */
      $files_found++;  /* Add this */
      if (!is_dir($products_image_directory . $file)) {
        if (substr($file, strrpos($file, '.')) == $file_extension) {
          if(preg_match('/\Q' . $products_image_base . '\E/i', $file) == 1) {
            if ($file != $products_image) {
              if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
                //  echo 'I AM A MATCH ' . $file . '<br>';
                $images_array[] = $file;
              } else {
                //  echo 'I AM NOT A MATCH ' . $file . '<br>';
              }
            }
          }
        }
      }
    }
    if (sizeof($images_array)) {
      sort($images_array);
    }
    $dir->close();
  }

I'd make it "prettier" but I can't remember how to 'style' colors and the color buttons aren't there right now!

26 Apr 2012, 8:48 PM
#3
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

Hi, thanks for this but its not working for me. to be fair i'm not yet on 1.5.0 yet, however the code is identical. When I implement this suggestion no images are shown at all? did it work for you or have you done this from theory?

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 8:54 AM
#4
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Limit additional images listed?

You could do it with CSS.

Set in the admin, max add images per row of 3, and then fix in the CSS the max height for the additional images container to the height of the first row, so all the other images aren't visible. Of course they are loaded etc, but not viewable by the user.

27 Apr 2012, 10:54 AM
#5
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

I prefer not to hide stuff. search engines dont like that sort of thing.

your initial idea looks like it should work but maybe its not quite coded right?

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 11:00 AM
#6
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

not sure if the array() part has the file names at that point?

if so could i implement something like this example:

$input = array("a", "b", "c", "d", "e");

$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 11:52 AM
#7
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Limit additional images listed?

philip937:

I prefer not to hide stuff. search engines dont like that sort of thing.

your initial idea looks like it should work but maybe its not quite coded right?

Your not hiding anything, its not a hidden div, its just a reduced sized div. The content is all there and accessible, and search engines only ignore (not penalise) hidden content if it is blantantly spamming, other wise the millions of sites with tabbed divs which use display:none would be ranked down.

27 Apr 2012, 12:34 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,119
Plugin Contributions:
56

Re: Limit additional images listed?

That's what I get for "punting". Here's an updated/corrected version, the $files_found count was misplaced before:

// Check for additional matching images   
$file_extension = $products_image_extension;   
$products_image_match_array = array();   
$files_found = 0;  /* Add this */  
 if ($dir = @dir($products_image_directory)) {     
  while ($file = $dir->read() && $files_found < 3) {  /* Change this */       
    if (!is_dir($products_image_directory . $file)) {        
      if (substr($file, strrpos($file, '.')) == $file_extension) {          
        if(preg_match('/\Q' . $products_image_base . '\E/i', $file) == 1) {             
          if ($file != $products_image) {               
            if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {                 
              //  echo 'I AM A MATCH ' . $file . '<br>';                
              $images_array[] = $file;
              $files_found++;  /* Add this */               
            } else {                 
              //  echo 'I AM NOT A MATCH ' . $file . '<br>';              
            }
          }
        }
      }
    }
  }
  if (sizeof($images_array)) {
       sort($images_array);
  }
  $dir->close();
}
27 Apr 2012, 2:24 PM
#9
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

lat9:

That's what I get for "punting". Here's an updated/corrected version, the $files_found count was misplaced before:

// Check for additional matching images
$file_extension = $products_image_extension;
$products_image_match_array = array();
$files_found = 0; /* Add this /
if ($dir = @dir($products_image_directory)) {
while ($file = $dir->read() && $files_found < 3) { /
Change this /
if (!is_dir($products_image_directory . $file)) {
if (substr($file, strrpos($file, '.')) == $file_extension) {
if(preg_match('/\Q' . $products_image_base . '\E/i', $file) == 1) {
if ($file != $products_image) {
if ($products_image_base . str_replace($products_image_base, '', $file) == $file) {
// echo 'I AM A MATCH ' . $file . '<br>';
$images_array[] = $file;
$files_found++; /
Add this */
} else {
// echo 'I AM NOT A MATCH ' . $file . '<br>';
}
}
}
}
}
}
if (sizeof($images_array)) {
sort($images_array);
}
$dir->close();
}


nope that still doesnt work :( outputs no images

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 2:58 PM
#11
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

SWEET! haha after all that all that had to be changed was that! perfect thanks mate. Im surprised that this isn't controllable from the admin!

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 3:04 PM
#13
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Limit additional images listed?

philip937:

SWEET! haha after all that all that had to be changed was that! perfect thanks mate. Im surprised that this isn't controllable from the admin!

Well in theory, if you only want 3 additional images, just don't upload the other 7 :)

27 Apr 2012, 3:09 PM
#14
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

hmm yeah i do have some that have none. so thats a problem.

How can I test if there is no images in the array?

tied this but doesnt work..

if ($num_images < 1) {
$num_images = sizeof($images_array);
} else {
// Build output based on images found
$num_images = 3;
}

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 3:11 PM
#15
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

haha was having a brian fart.

this is the fix

if ($num_images < 3) {
$num_images = sizeof($images_array);
} else {
// Build output based on images found
$num_images = 3;
}

Phil Rogers
A problem shared is a problem solved.

27 Apr 2012, 3:32 PM
#16
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Limit additional images listed?

philip937:

haha was having a brian fart.

this is the fix

if ($num_images < 3) {
$num_images = sizeof($images_array);
} else {
// Build output based on images found
$num_images = 3;
}

Wont that also not show any additional images for products that only have 2?

27 Apr 2012, 3:40 PM
#17
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

no the logic is

if the number of images in the array is less than 3 then do what it normally does, i.e $num_images = sizeof($images_array); other wise if there are 4 or more excecute the mod that you said which instead of building based on the actual number of images, it only buoilds up to 3.

make sense? works a treat anyway :)

Thanks for you help dgent

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 3:26 PM
#19
wwrepair avatar

wwrepair

New Zenner

Join Date:
Jun 2012
Posts:
92
Plugin Contributions:
0

Re: Limit additional images listed?

Philip937,

I am happy to hear you found the solutions for this! Can you please show me exactly where you added this code in includes/modules/additional_images.php? Or if you removed anything? Thank you!

12 Feb 2013, 3:34 PM
#20
philip937 avatar

philip937

Totally Zenned

Join Date:
Aug 2009
Location:
Bedford, England
Posts:
968
Plugin Contributions:
0

Re: Limit additional images listed?

WWRepair:

Philip937,

I am happy to hear you found the solutions for this! Can you please show me exactly where you added this code in includes/modules/additional_images.php? Or if you removed anything? Thank you!

cant remeber off the top of my head but I think I just added this code either after where $num_images is defined

so basically what its doing is saying if there is less than 3 images then the amount of images should be default i.e sizeof($image_array)

if ($num_images < 3) {
$num_images = sizeof($images_array);
}

otherwise lets fool it into thinking that there are only a max of 3..

 else {
// Build output based on images found
$num_images = 3;
}

so full code would be:

if ($num_images < 3) {
$num_images = sizeof($images_array);
}else {
// Build output based on images found
$num_images = 3;
}

hope this helps, if you get stuck let me know any I will pull more code from my file I modified. what version are you using also, just incase the code has been changed from the version I was playing with!

Phil Rogers
A problem shared is a problem solved.