Author Topic: TIP: Count number of images in gallery with php  (Read 7390 times)

0 Members and 1 Guest are viewing this topic.

Offline Syrinx

TIP: Count number of images in gallery with php
« on: 19. January 2009, 06:42:24 »
This will count how many .jpg and .gif images there are in a listing's gallery, you can use this in the vcard or detail view templates:

<?php $gallery_images count(glob("images/com_sobi2/gallery/$mySobi->id/$mySobi->id{_image*.gif,_image*.jpg}"GLOB_BRACE)); ?>

You can then show the # of images by using:

<?php echo $gallery_images?>

You can also test/use the variable $gallery_images in other php operations ("if" statement to show gallery tab etc).

« Last Edit: 19. January 2009, 06:45:05 by Syrinx »
Country: United States United States |  OS: Unknown Unknown Browser: Unknown Unknown | View Profile

Offline jonnyt

Re: TIP: Count number of images in gallery with php
« Reply #1 on: 24. June 2009, 17:40:19 »
I cant get this working on my vCard template.

Any ideas why this might be? It works fine on my details view template.

http://test.harrogatebuildingtrades.co.uk/index.php/Search-Trades/Air-Conditioning-Harrogate.html

On the page above if you scroll to the bottom and go to Gold Listing example, this listing has images so should show 5 in the image count.
Country: United Kingdom United Kingdom |  OS: Unknown Unknown Browser: Unknown Unknown | View Profile

Offline Syrinx

Re: TIP: Count number of images in gallery with php
« Reply #2 on: 24. June 2009, 17:46:57 »
I cant get this working on my vCard template.

Any ideas why this might be? It works fine on my details view template.

Make sure this line near the top of the template isn't commented out:
$mySobi = new sobi2( $id );

If it looks like this:

// $mySobi = new sobi2( $id );

Remove the two slashes
Country: United States United States |  OS: Unknown Unknown Browser: Unknown Unknown | View Profile

Offline maste-agent

Re: TIP: Count number of images in gallery with php
« Reply #3 on: 23. February 2010, 18:31:53 »
Hello Syrinx,

I have self-made gallery and I'm pulling images from folders manually.

First, I get the number of images (using your code) than iI use FOR loop to echo all images.
I'm using variable from FOR loop to tuck correct image number.

Here is the code:

Code: [Select]
<?php $gallery_images count(glob("images/com_sobi2/gallery/$mySobi->id/$mySobi->id{_image*.png,_image*.jpg}"GLOB_BRACE)); ?>
<?php if ($gallery_images == 0) {
echo "<strong>Napomena: </strong>Galerija nije dodana ili ne sadrži slike.";
?>

<?php
$images_limit $gallery_images;
for ( $counter 1$counter <= $images_limit$counter += 1) { ?>

<a href='<?php echo JURI::base(); ?>images/com_sobi2/gallery/<?php echo $mySobi->id?>/<?php echo $mySobi->id?>_image_<?php echo $counter ?>.jpg' title='Konzum 3' onclick="return hs.expand(this)"><img src='<?php echo JURI::base(); ?>images/com_sobi2/gallery/<?php echo $mySobi->id?>/<?php echo $mySobi->id?>_thumb_<?php echo $counter?>.jpg' alt='Konzum 3' class="thumb" title='Konzum 3' /></a>
<?php ?>

This code is working but ONLY for jpg images.
Code: [Select]
_image_<?php echo $counter ?>.jpg

I would love to have code which will detect image extension (.png  or  .jpg). and than create this:

_image_<?php echo $counter ?>.png

or this

_image_<?php echo $counter ?>.jpg


Can You tell me how can I do this?
My SOBI2 powered website: www.quickinfo.ba   |   it's all about SOBI2
Design and Development: www.reflect.ba
Country: Bosnia and Herzegovina Bosnia and Herzegovina |  OS: Windows 7/Server 2008 R2 Windows 7/Server 2008 R2 |  Browser: Firefox 3.5.8 Firefox 3.5.8 | View Profile Reflect Design & Development

Tags: