Last active
December 24, 2015 10:19
-
-
Save hagatorn/5554230 to your computer and use it in GitHub Desktop.
Alternative gallery with for kirby: uses a central csv table and image bank. In the text file for your page type ---- imagelist: yourfilename1, yourfilename2, yourfilename3,
Allows for much easier page construction for large site that you may otherwise use a db for
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 /*?>* function csv_to_array | |
* @link http://gist.github.com/385876 | |
* @author Jay Williams <http://myd3.com/> | |
* @copyright Copyright (c) 2010, Jay Williams<?php */?> | |
<?php | |
$imagelist= $page->imagelist(); | |
if ($imagelist != ''){ | |
function csv_to_array($filename='', $delimiter=',') { | |
if (!file_exists($filename)) | |
return 'not exist'; | |
if (!is_readable($filename)) | |
return 'not readable'; | |
$header = NULL; | |
$data = array(); | |
if (($handle = fopen($filename, 'r')) !== FALSE) { | |
while (($row = fgetcsv($handle, 200, $delimiter)) !== FALSE) { | |
if (!$header) | |
$header = $row; | |
else | |
$data[] = array_combine($header, $row); | |
} | |
fclose($handle); | |
} | |
return $data; | |
} | |
function createModels($data) | |
{ | |
$newRow = array(); | |
$newData = array(); | |
if (is_array($data)){ | |
foreach($data as $rowIndex => $row){ | |
if(is_array($row)){ | |
$newRowIndex = $row['Stock book code']; | |
} | |
$newData[$newRowIndex] = array_merge($newRow, $row); | |
} | |
} | |
return $newData; | |
} | |
$imageInfoArray = csv_to_array('assets/artistswork/imagemeta.csv'); | |
$imageMetaIndexed = createModels($imageInfoArray); ?> | |
<div id="gallery" class="row-fluid"> | |
<ul class="gallery"> | |
<?php | |
$galItemid = 1; | |
$imagelistitem= explode(", ", $imagelist); | |
foreach ($imagelistitem as $image): ?> | |
<li> | |
<div id="galItem<?php echo $galItemid?>" class="galleryItem row-fluid"> | |
<div class="imageBox span8"><img src="<?php echo url('assets/artistswork/450/').$image.'.jpg' ?>" alt="<?php echo $imageMetaIndexed[$image]['Work Title']?>"></div> | |
<div class="imageMetaBox span4"> | |
<span class="workTitle"><?php echo $imageMetaIndexed[$image]['Work Title']?></span> | |
<span class="workDate"><?php echo $imageMetaIndexed[$image]['Date']?></span> | |
<span class="workMaterial"> | |
<?php if (($imageMetaIndexed[$image]['materials']) != '0') {echo ($imageMetaIndexed[$image]['materials']);} | |
?> | |
</span> | |
<span class="workDimensions"> | |
<?php if (($imageMetaIndexed[$image]['width']) != '0') { echo ($imageMetaIndexed[$image]['width'].' x '.$imageMetaIndexed[$image]['height']); }?> | |
</span> | |
<span class="workPrice"><?php if (($imageMetaIndexed[$image]['Ownership']) != '0') {echo $imageMetaIndexed[$image]['Ownership'];}?></span> | |
</div> | |
</div> | |
</li> | |
<?php | |
$galItemid += 1; | |
endforeach ; ?> | |
</ul> | |
</div> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I think this may solve my problem: lots of images with lots of associated data. In the past I've used an xml file. But now that I'm switching to kirby, I need to re-think my approach.
Do you have any demo or walk-through on this?
Thanks