Forums / General Questions / Limit additional images listed?

Limit additional images listed?

Views: 3,126

Results 21 to 34 of 34
12 Feb 2013, 3:55 PM
#21
wwrepair avatar

wwrepair

New Zenner

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

Limit additional images listed?

I tried plugging it in a couple of places and it didn't work. I am using v 1.5.0. I would greatly appreciate it if you could tell me exactly where you added it. Thank you so much!

12 Feb 2013, 4:30 PM
#22
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

pop the content of the file between the php tags one here so i have the doe in front of me and i'll have a butchers, otherwise i'll take a look later :)

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 6:27 PM
#23
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

replace this:

// Build output based on images found
$num_images = sizeof($images_array);
$list_box_contents = '';
$title = '';

with this:

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

that works. so if it isn't working for you, check that your template isn't overriding the file in
includes/modules/YOUR_TEMPLATE/additional_images.php

obviously you change the 3 for which ever value you want..

Enjoy!

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 6:32 PM
#24
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Limit additional images listed?

check that your template isn't overriding the file in
includes/modules/YOUR_TEMPLATE/additional_images.php Remember that you should always put modified versions of files in template override folders wherever the override facility exists, so your version should be in /includes/modules/YOUR_TEMPLATE/additional_images.php.

12 Feb 2013, 6:34 PM
#25
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

gjh42:

Remember that you should always put modified versions of files in template override folders wherever the override facility exists, so your version should be in /includes/modules/YOUR_TEMPLATE/additional_images.php.

yes naughty naughty me! this is very true. if you dont have an override file... make one for this modification! thanks gjh42 :blush:

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 6:40 PM
#26
wwrepair avatar

wwrepair

New Zenner

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

Re: Limit additional images listed?

philip937:

replace this:

// Build output based on images found
$num_images = sizeof($images_array);
$list_box_contents = '';
$title = '';

> 
> with this:
> ```php
// Build output based on images found
$num_images = sizeof($images_array);
if ($num_images < 3) {
$num_images = sizeof($images_array);
} else {
// Build output based on images found
$num_images = 3;
}
$list_box_contents = '';
$title = '';

that works. so if it isn't working for you, check that your template isn't overriding the file in
includes/modules/YOUR_TEMPLATE/additional_images.php

obviously you change the 3 for which ever value you want..

Enjoy!

Darn, It didn't work for me, it just didn't show any additional images and the side boxes on the right didn't load. I just turned off the additional images instead. It was loading to many for my mobile view which is why I wanted to limit it. I appreciate your help and thank you very much for your time. Oh well :(

12 Feb 2013, 6:47 PM
#27
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Limit additional images listed?

That indicates a PHP syntax error in your modification. Did the footer also disappear? Check your /cache/ (/logs/ in v1.5.1) folder and post the latest myDebug file.

12 Feb 2013, 6:52 PM
#28
wwrepair avatar

wwrepair

New Zenner

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

Re: Limit additional images listed?

gjh42:

That indicates a PHP syntax error in your modification. Did the footer also disappear? Check your /cache/ (/logs/ in v1.5.1) folder and post the latest myDebug file.

Yes the footer did also disappear. This is what the latest one says:
[12-Feb-2013 11:32:27] PHP Parse error: syntax error, unexpected T_IF in /home8/wwrepair/public_html/parts/includes/modules/additional_images.php on line 1

12 Feb 2013, 6:55 PM
#29
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

line 1!? what on earth could have happened there..? can you post the whole contents of your additional_images.php file please?

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 6:58 PM
#30
wwrepair avatar

wwrepair

New Zenner

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

Re: Limit additional images listed?

philip937:

line 1!? what on earth could have happened there..? can you post the whole contents of your additional_images.php file please?

Ya, I saw that too and was like, what?!? This is what I have uploaded right now without any modifications

<?php

/**

 * additional_images module

 *

 * Prepares list of additional product images to be displayed in template

 *

 * @package templateSystem

 * @copyright Copyright 2003-2011 Zen Cart Development Team

 * @copyright Portions Copyright 2003 osCommerce

 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

 * @version $Id: additional_images.php 18697 2011-05-04 14:35:20Z wilt $

 */

if (!defined('IS_ADMIN_FLAG')) {

  die('Illegal Access');

}

if (!defined('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE')) define('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE','Yes');

$images_array = array();



// do not check for additional images when turned off

if ($products_image != '' && $flag_show_product_info_additional_images != 0) {

  // prepare image name

  $products_image_extension = substr($products_image, strrpos($products_image, '.'));

  $products_image_base = str_replace($products_image_extension, '', $products_image);



  // if in a subdirectory

  if (strrpos($products_image, '/')) {

    $products_image_match = substr($products_image, strrpos($products_image, '/')+1);

    //echo 'TEST 1: I match ' . $products_image_match . ' - ' . $file . ' -  base ' . $products_image_base . '<br>';

    $products_image_match = str_replace($products_image_extension, '', $products_image_match) . '_';

    $products_image_base = $products_image_match;

  }



  $products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));

  if ($products_image_directory != '') {

    $products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/";

  } else {

    $products_image_directory = DIR_WS_IMAGES;

  }



  // Check for additional matching images

  $file_extension = $products_image_extension;

  $products_image_match_array = array();

  if ($dir = @dir($products_image_directory)) {

    while ($file = $dir->read()) {

      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();

  }

}


// Build output based on images found

$num_images = sizeof($images_array);

$list_box_contents = '';

$title = '';



if ($num_images) {

  $row = 0;

  $col = 0;

  if ($num_images < IMAGES_AUTO_ADDED || IMAGES_AUTO_ADDED == 0 ) {

    $col_width = floor(100/$num_images);

  } else {

    $col_width = floor(100/IMAGES_AUTO_ADDED);

  }



  for ($i=0, $n=$num_images; $i<$n; $i++) {

    $file = $images_array[$i];

    $products_image_large = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory) . str_replace($products_image_extension, '', $file) . IMAGE_SUFFIX_LARGE . $products_image_extension;

    $flag_has_large = file_exists($products_image_large);

    $products_image_large = ($flag_has_large ? $products_image_large : $products_image_directory . $file);

    $flag_display_large = (IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE == 'Yes' || $flag_has_large);

    $base_image = $products_image_directory . $file;

    $thumb_slashes = zen_image(addslashes($base_image), addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);

    $thumb_regular = zen_image($base_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);

    $large_link = zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large);



    // Link Preparation:

    $script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . str_replace($products_image_large, urlencode(addslashes($products_image_large)), $large_link) . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>';



    $noscript_link = '<noscript>' . ($flag_display_large ? '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large) . '" target="_blank">' . $thumb_regular . '<br /><span class="imgLinkAdditional">' . TEXT_CLICK_TO_ENLARGE . '</span></a>' : $thumb_regular ) . '</noscript>';



    //      $alternate_link = '<a href="' . $products_image_large . '" onclick="javascript:popupWindow(\''. $large_link . '\') return false;" title="' . $products_name . '" target="_blank">' . $thumb_regular . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>';



    $link = $script_link . "\n      " . $noscript_link;

    //      $link = $alternate_link;



    // List Box array generation:

    $list_box_contents[$row][$col] = array('params' => 'class="additionalImages centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',

                                           'text' => "\n      " . $link);

    $col ++;

    if ($col > (IMAGES_AUTO_ADDED -1)) {

      $col = 0;

      $row ++;

    }

  } // end for loop

} // endif
12 Feb 2013, 7:20 PM
#31
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

<?php 

/** 

 * additional_images module 

 * 

 * Prepares list of additional product images to be displayed in template 

 * 

 * @package templateSystem 

 * @copyright Copyright 2003-2011 Zen Cart Development Team 

 * @copyright Portions Copyright 2003 osCommerce 

 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 

 * @version $Id: additional_images.php 18697 2011-05-04 14:35:20Z wilt $ 

 */ 

if (!defined('IS_ADMIN_FLAG')) { 

  die('Illegal Access'); 

} 

if (!defined('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE')) define('IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE','Yes'); 

$images_array = array(); 



// do not check for additional images when turned off 

if ($products_image != '' && $flag_show_product_info_additional_images != 0) { 

  // prepare image name 

  $products_image_extension = substr($products_image, strrpos($products_image, '.')); 

  $products_image_base = str_replace($products_image_extension, '', $products_image); 



  // if in a subdirectory 

  if (strrpos($products_image, '/')) { 

    $products_image_match = substr($products_image, strrpos($products_image, '/')+1); 

    //echo 'TEST 1: I match ' . $products_image_match . ' - ' . $file . ' -  base ' . $products_image_base . '<br>'; 

    $products_image_match = str_replace($products_image_extension, '', $products_image_match) . '_'; 

    $products_image_base = $products_image_match; 

  } 



  $products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/'))); 

  if ($products_image_directory != '') { 

    $products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image) . "/"; 

  } else { 

    $products_image_directory = DIR_WS_IMAGES; 

  } 



  // Check for additional matching images 

  $file_extension = $products_image_extension; 

  $products_image_match_array = array(); 

  if ($dir = @dir($products_image_directory)) { 

    while ($file = $dir->read()) { 

      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(); 

  } 

} 


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

$list_box_contents = ''; 

$title = ''; 



if ($num_images) { 

  $row = 0; 

  $col = 0; 

  if ($num_images < IMAGES_AUTO_ADDED || IMAGES_AUTO_ADDED == 0 ) { 

    $col_width = floor(100/$num_images); 

  } else { 

    $col_width = floor(100/IMAGES_AUTO_ADDED); 

  } 



  for ($i=0, $n=$num_images; $i<$n; $i++) { 

    $file = $images_array[$i]; 

    $products_image_large = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory) . str_replace($products_image_extension, '', $file) . IMAGE_SUFFIX_LARGE . $products_image_extension; 

    $flag_has_large = file_exists($products_image_large); 

    $products_image_large = ($flag_has_large ? $products_image_large : $products_image_directory . $file); 

    $flag_display_large = (IMAGE_ADDITIONAL_DISPLAY_LINK_EVEN_WHEN_NO_LARGE == 'Yes' || $flag_has_large); 

    $base_image = $products_image_directory . $file; 

    $thumb_slashes = zen_image(addslashes($base_image), addslashes($products_name), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); 

    $thumb_regular = zen_image($base_image, $products_name, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT); 

    $large_link = zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large); 



    // Link Preparation: 

    $script_link = '<script language="javascript" type="text/javascript"><!--' . "\n" . 'document.write(\'' . ($flag_display_large ? '<a href="javascript:popupWindow(\\\'' . str_replace($products_image_large, urlencode(addslashes($products_image_large)), $large_link) . '\\\')">' . $thumb_slashes . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>' : $thumb_slashes) . '\');' . "\n" . '//--></script>'; 



    $noscript_link = '<noscript>' . ($flag_display_large ? '<a href="' . zen_href_link(FILENAME_POPUP_IMAGE_ADDITIONAL, 'pID=' . $_GET['products_id'] . '&pic=' . $i . '&products_image_large_additional=' . $products_image_large) . '" target="_blank">' . $thumb_regular . '<br /><span class="imgLinkAdditional">' . TEXT_CLICK_TO_ENLARGE . '</span></a>' : $thumb_regular ) . '</noscript>'; 



    //      $alternate_link = '<a href="' . $products_image_large . '" onclick="javascript:popupWindow(\''. $large_link . '\') return false;" title="' . $products_name . '" target="_blank">' . $thumb_regular . '<br />' . TEXT_CLICK_TO_ENLARGE . '</a>'; 



    $link = $script_link . "\n      " . $noscript_link; 

    //      $link = $alternate_link; 



    // List Box array generation: 

    $list_box_contents[$row][$col] = array('params' => 'class="additionalImages centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"', 

                                           'text' => "\n      " . $link); 

    $col ++; 

    if ($col > (IMAGES_AUTO_ADDED -1)) { 

      $col = 0; 

      $row ++; 

    } 

  } // end for loop 

} // endif

so your modified file should be like I have just posted above..^^^ ?

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 7:25 PM
#32
wwrepair avatar

wwrepair

New Zenner

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

Re: Limit additional images listed?

Genius!! Works beautifully! Thank you so much!

12 Feb 2013, 7:27 PM
#33
philip937 avatar

philip937

Totally Zenned

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

Re: Limit additional images listed?

maybe i posted the code wrong earlier? or perhaps you copied it over wrong, but hey whichever, glad its working for you :D

Phil Rogers
A problem shared is a problem solved.

12 Feb 2013, 7:30 PM
#34
wwrepair avatar

wwrepair

New Zenner

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

Re: Limit additional images listed?

I'm sure it wasn't you, I must have done something wrong. Thank you so much!!