Created
April 10, 2014 04:33
-
-
Save dsebao/10342788 to your computer and use it in GitHub Desktop.
Show the first image of every folders finding in a root dir in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
In this example bfithumb (https://github.com/bfintal/bfi_thumb) is | |
include in functions.php for the thumbnails | |
The folders have the id gallery, name of the gallery and the date in his name. | |
eg: 123_mytitle_02.12.2014 | |
*/ | |
$search = dirname(__FILE__) . "/{foldername}/"; | |
$ffs = scandir($search); | |
foreach($ffs as $ff){ | |
//i don´t want this foolders | |
if($ff != '.' && $ff != '..' && $ff !== ".DS_Store"){ | |
if(is_dir($search.'/'.$ff)){ | |
//save folders in an array | |
$folders[] = $ff; | |
} | |
} | |
} | |
//Create the loop for every folders finded | |
for ($i = 0; $i < sizeof($folders); $i++){ | |
$data = explode("_",$folders[$i]); | |
$files = glob($search . $folders[$i] . '/*.jpg'); | |
if(!empty($files)){ | |
sort($files); | |
$url = get_bloginfo('template_url') . '/{foldername}/' . $folders[$i] . '/'; | |
$filename = basename($files[0]); | |
$imgurl = $url . $filename; | |
$params = array( 'width' => 80,'height' => 80 );?> | |
<li> | |
<h1><?php echo $data[1];?></h1> | |
<a href="?gallery=<?php echo $folders[$i];?>"><img src="<?php echo bfi_thumb( $imgurl, $params )?>" alt=""></a> | |
<h3><?php echo $data[2];?></h3> | |
</li> | |
<?php | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment