• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Instant Gallery ( Latest Uploads )

wethead

Chevereto Member
Hi

Its not a huge plugin or anything, BUT if you want to show a gallery anywhere on your site add the following

Instant Gallery ( Latest Uploads )

We will be making a "Gallery Page"

You can also use this function in other places in your theme I.e home page / footer etc

Step One:

Create a new page called gallery.php in text editor:

Then add the following code:

Code:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
<?php include_theme_header(); ?>
    <div id="content" class="pages page_gallery">


<?php
$largeArray = glob("images/*.jpg");
$counter = 0; 
foreach (array_slice(glob("images/thumbs/*.jpg"),0,60) as $thumb) {
echo ("<div class='thumbgall'><a href='$largeArray[$counter]'><img src='$thumb'/></a></div>");
$counter++;
}
?>
   </div>
<?php include_theme_footer(); ?>

Step Two:

Save as gallery.php


Step Three:

Upload gallery.php to your themes/YOURtheme/pages/

Step Four:

EDIT:

themes/YOURtheme/pages//pages_config.php

find:

Code:
'contact'    => array('live' => true, 'title' => 'Contact'),

add under:

Code:
'gallery'    => array('live' => true, 'title' => 'Gallery'),





If you want to style it, add this to your style.css


Code:
.thumbgall{padding: 10px 5px 10px 5px;display:inline;}


The function:



To change number of images to display edit: ( The bold )



b("images/thumbs/*.jpg"),0,60) as $thumb) {



Code:
<?php
$largeArray = glob("images/*.jpg");
$counter = 0; 
foreach (array_slice(glob("images/thumbs/*.jpg"),0,60) as $thumb) {
echo ("<div class='thumbgall'><a href='$largeArray[$counter]'><img src='$thumb'/></a></div>");
$counter++;
}

ENJOY!

Here is a screenshot of what it will produce

WvBH.png
 
ALSO:

If you wanted to display like ( 8 ) images on your home page:

find on: /yourtheme/index.php


Code:
show_lang_txt('txt_cancel'); ?></a></div>
            </div>
        </form>

add under:

Code:
<br />
<h1>Recent Uploads</h1>

<p style="padding: 10px 0px 0px 0px;">

<?php
$largeArray = glob("images/*.jpg");
$counter = 0; 
foreach (array_slice(glob("images/thumbs/*.jpg"),0,8) as $thumb) {
echo ("<div class='thumbgall'><a href='$largeArray[$counter]'><img src='$thumb'/></a></div>");
$counter++;
}

?>

</p>
Like so:

iAxfH.png
 
Also, you may recheck your code, because it is really inefficient. You could do the same results with using much less server ressources.
 
Danny.Domb said:
Also, you may recheck your code, because it is really inefficient. You could do the same results with using much less server ressources.



Feel free to correct me :)
 
This sorts images by their name. Is there any way to change that so the images are sorted by upload date instead? I'd prefer to show images in the order they were uploaded, i.e. most recent first.

Thanks for the code, btw.
 
since the mod doesn't use a database to store the images data i guess you can use the php function filectime

hope this helps.
 
kiely said:
This sorts images by their name. Is there any way to change that so the images are sorted by upload date instead? I'd prefer to show images in the order they were uploaded, i.e. most recent first.

Thanks for the code, btw.


Not really, as the guy above me said there is no DB......so there is no _time_stamp.....
 
wethead said:
kiely said:
This sorts images by their name. Is there any way to change that so the images are sorted by upload date instead? I'd prefer to show images in the order they were uploaded, i.e. most recent first.

Thanks for the code, btw.


Not really, as the guy above me said there is no DB......so there is no _time_stamp.....

but you can use the function filectime() for this ;)
 
Darkmax said:
wethead said:
kiely said:
This sorts images by their name. Is there any way to change that so the images are sorted by upload date instead? I'd prefer to show images in the order they were uploaded, i.e. most recent first.

Thanks for the code, btw.


Not really, as the guy above me said there is no DB......so there is no _time_stamp.....

but you can use the function filectime() for this ;)


Yes, Yes you can, I am new learning all the advanced functions, BUT I like to share code as I go, So I can be helpful to others :)

If anyone is looking for a free image gallery, here is one I found 2 days ago and it works nice !


http://www.lateralcode.com/create-a-simple-picture-gallery-using-php/



You can download the files from the guys site above ( not my website )

Hope this helps, but with that script above and some time you can create something cool.

Code is like poetry , its fun and rewarding , always keep trying and you'll always get better is my motto :)
 
Thanks for sharing . IT works great .

I'm just wondering if there is a chance that when users click on the tumbs it will show the full picture sth like LightBox image viewer .
 
Danny.Domb said:
Also, you may recheck your code, because it is really inefficient. You could do the same results with using much less server ressources.


Like how?

Can someone like yourself provide an example?

I
 
how to show "Recent Images" ???

if u want to show images on ur index.php it will never change ! the first X uploaded images will be shows up ALWAYS !!!
 
My gallery version with file sort by upload time :)

Code:
<?php if(!defined('access') or !access) die('This file cannot be directly accessed.'); ?>
<?php include_theme_header(); ?>
<div id="content" class="pages page_gallery">

<?php
function gallery_block($total)
{
    $img_dir = __CHV_FOLDER_IMAGES__.'/';
    $tmb_dir = __CHV_FOLDER_THUMBS__.'/';
    
    $counter = 1;
    $_times = $images = array();
    $_files = glob($img_dir."{*.gif,*.jpg,*.png}", GLOB_BRACE);

    foreach ($_files as $i => $file) { $_times[$i] = filemtime($file); }
    arsort($_times);

    foreach ($_times as $i => $time) 
    {
        if ($total < $counter++) break;
        $images[] = basename($_files[$i]);
    }
    foreach ($images as $image)
    {
        echo '<div class="thumbgall"><a href="/?v='.$image.'"><img src="'.$tmb_dir.$image.'"/></a></div>';
    }
}
gallery_block(60);
?>

</div>
<?php include_theme_footer(); ?>
 
A much faster way, but you should have the rights to use the system() function on your hosting

Code:
function gallery_block_sys($total)
{
    $img_dir = __CHV_FOLDER_IMAGES__.'/';
    $tmb_dir = __CHV_FOLDER_THUMBS__.'/';

    ob_start();
    system("ls -t {$img_dir} | grep -i -e 'jpg$' -e 'png$' -e 'gif$'");    

    $files = split("\n", ob_get_clean());
    $counter = 1;
    foreach ($files as $file)
    {
        if ($total < $counter++) break;

        $image = trim($file);
        if (is_file($img_dir.$image))
        {
           echo '<div class="thumbgall"><a href="/?v='.$image.'"><img src="'.$tmb_dir.$image.'"/></a></div>';
        }
    }
}
gallery_block_sys(60);
 
Wink said:
A much faster way, but you should have the rights to use the system() function on your hosting

using the system function is never recommanded, even if you think that its perfectly safe when no user input is allowed, it is not... PHP is never completly safe and injecting code / overwritting variables is possible...

And if somebody were to overwrite one of your variable he could send code directly to your system command... Not a great idea really
 
Back
Top