News:

Looking for documentation? Take a look on our wiki

Main Menu

How to display the real sum of displayed additional images?

Started by hazael, July 29, 2018, 16:02:08 PM

Previous topic - Next topic

hazael

I hid some of the images using the class names - My modification:

$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?

Jörgen

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
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

hazael

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;

Jörgen

Nice that You got it solved

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Studio 42

Id dont know if this is the core code but
$i < count($this->product->images)
is bad because he count on each iteration
$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

$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;