VirtueMart Forum

VirtueMart 2 + 3 => General Questions => Topic started by: hazael on July 29, 2018, 16:02:08 pm

Title: How to display the real sum of displayed additional images?
Post by: hazael on July 29, 2018, 16:02:08 pm
I hid some of the images using the class names - My modification:
Code: [Select]
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
for ($i = $start_image; $i < count($this->product->images); $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
My problem - variable $i  shows 100% of images (with hidden ones).  How to do it so that the variable $i shows the actual number of display images?
Title: Re: How to display the real sum of displayed additional images?
Post by: Jörgen on July 29, 2018, 16:41:13 pm
If you can hide images as your code sais. Simply create a new var $iv that counts the visible images. Simply put in your loop.
Regards
Jörgen @ Kreativ Fotografi
Title: Re: How to display the real sum of displayed additional images?
Post by: hazael on July 29, 2018, 17:20:19 pm
OMG. I'm stupid - it's simple :)

Quote
$real = 0;
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
for ($i = $start_image; $i < count($this->product->images); $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
$real++
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
echo $real;
Title: Re: How to display the real sum of displayed additional images?
Post by: Jörgen on July 29, 2018, 21:19:21 pm
Nice that You got it solved

Jörgen @ Kreativ Fotografi
Title: Re: How to display the real sum of displayed additional images?
Post by: Studio 42 on July 30, 2018, 00:17:33 am
Id dont know if this is the core code but
Code: [Select]
$i < count($this->product->images)is bad because he count on each iteration
Code: [Select]
$totalimage = count($this->product->images);
for ($i = $start_image; $i <  $totalimage; $i++) {
is a better code
And you dont need to count in the loop
YOu can do
$real = $totalimage-$start_image;
The complet code is then

Code: [Select]
$start_image = VmConfig::get('add_img_main', 1) ? 0 : 1;
$totalimage = count($this->product->images);
$real = $totalimage-$start_image;
for ($i = $start_image; $i < $totalimage; $i++) {
$image = $this->product->images[$i];
if ((strstr($image->file_class, "class-1")!==False) || (strstr($image->file_class, "class-2")!==False)) {
echo  $image->displayMediaThumb("",true,"rel='vm-additional-images'",true,$image->file_description);
}}
echo $real;