1
0
Fork 0
web-jbeyerstedt/site/snippets/plg-carousel.php

67 lines
2.7 KiB
PHP
Raw Permalink Normal View History

<?php
// -------------------------------------------
// kirby snippet GENERAL
// Title: plg-carousel
// funct: twitter bootstap carousel for photos in carousel subpage (folder)
// modified for bootstrap 4 !
// copyright: Jannik Beyerstedt | http://jannikbeyerstedt.de | code@jannikbeyerstedt.de
// license: http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 License
// usage:
// snippet('plg-carousel', array('currentPage'=>$page,
// 'preNormal'=>'optional html to add before carousel',
// 'preAlt'=>'html if snippet is not displayed (for other styles)'))
// and set these constants in config.php:
//c::set('plg_carousel.sort', 'sort'); // sortBy parameter: sort, title, etc.
//c::set('plg_carousel.dir', 'asc'); // sortBy direction: asc, desc
// -------------------------------------------
// display carousel only if there are images
$carouselFolder = $currentPage->children()->find('carousel');
if (!isset($preNormal)) {$preNormal="";}
if (!isset($preAlt)) {$preAlt="";}
$sort = c::get('plg_carousel.sort', 'title');
$sdir = c::get('plg_carousel.dir', 'desc');
// if folder exists
if (!(false==$carouselFolder) && ($carouselFolder->hasImages())) : echo $preNormal
?>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<?php $n=-1; foreach($carouselFolder->images()->sortBy($sort, $sdir) as $image): $n++; ?>
<li data-target="#myCarousel" data-slide-to="<?php echo $n ?>" class="<?php if($n==0) echo ' active' ?>"></li>
<?php endforeach ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php $n=-1; foreach($carouselFolder->images()->sortBy($sort, $sdir) as $image): $n++; ?>
<div class="carousel-item<?php if($n==0) echo ' active' ?>">
<img src="<?php echo $image->url() ?>" alt="<?php echo $image->title()->html() ?>" />
<?php if(($image->heading() != "") || ($image->caption() != "")) : ?>
<div class="carousel-caption">
<?php if($image->heading() != "") : ?><h3><?php echo $image->heading()->kirbytext() ?></h3><?php endif; ?>
<?php echo $image->caption()->kirbytext() ?>
</div>
<?php endif; ?>
</div>
<?php endforeach ?>
</div>
<a class="carousel-control-prev" href="#myCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#myCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php else : echo $preAlt ?>
<?php endif ?>