Skip to content

Instantly share code, notes, and snippets.

@gyrus
Last active December 12, 2015 04:29
Show Gist options
  • Save gyrus/4714922 to your computer and use it in GitHub Desktop.
Save gyrus/4714922 to your computer and use it in GitHub Desktop.
A sophisticated carousel system for use with the Pilau Starter theme (https://github.com/pilau/starter). Also dependent on the Developer's Custom Fields plugin (https://github.com/gyrus/WordPress-Developers-Custom-Fields). Successfully tested, but there may be some glitches to iron out in integrating - it was developed for one project and never …
<?php
/**
* Front page
*/
// Get carousels data
$pilau_carousels_data = get_option( 'pilau_carousels_data' );
// Default to all
$pilau_initial_carousel = 'all';
if ( isset( $_COOKIE['pilau_home_carousel'] ) ) {
$pilau_initial_carousel = $_COOKIE['pilau_home_carousel'];
} else if ( isset( $_REQUEST['carousel'] ) ) {
$pilau_initial_carousel = $_REQUEST['carousel'];
}
?>
<?php get_header(); ?>
<div role="main" id="main">
<?php /* Pass carousels data along for client-side JS */ ?>
<aside id="carousels" data-carousels="<?php echo implode( ' ', array_keys( $pilau_carousels_data ) ); ?>" role="complementary"><div id="carousels-window">
<?php
/*
* No-JS clients just get the initial carousel - other carousels are loaded via AJAX
*/
echo pilau_carousel( $pilau_initial_carousel );
?>
</div></aside>
</div><!-- #main -->
<?php get_footer(); ?>
require( dirname( __FILE__ ) . '/carousel.php' );
add_action( 'after_setup_theme', 'pilau_setup' );
function pilau_setup() {
add_image_size( 'carousel-horizontal', 466, 243, false );
add_image_size( 'carousel-vertical', 306, 256, false );
add_image_size( 'carousel-square', 226, 188, true );
}
/*
IE7 hacks
*/
.js .home #carousels .scroll {
background: url("../img/bg-ie-transparent-white.png");
}
/* Front-end-only styles */
.js .home {
// Carousels
#carousels {
position: relative;
height: @carousel-height + ( @carousel-gutter * 2 ) + @carousel-controls-height;
width: 100%;
padding: 0;
background-color: @color-background-grey-dark;
text-align: center;
#carousels-controls {
position: relative;
height: @carousel-controls-height;
width: @width-wrapper;
margin: 0 auto;
text-align: left;
.FontBold( .9em );
color: lighten( @color-text-light, 10% );
}
#carousels-nav {
padding: @carousel-gutter 0 0 @carousel-gutter;
p, li {
.InlineBlock();
margin-right: @carousel-gutter;
}
ul {
text-transform: uppercase;
.InlineBlock();
li {
a {
padding: 2px 5px;
color: #fff;
&:hover, &:focus {
background-color: @color-pink;
text-decoration: none;
}
}
&.active a {
color: @color-pink;
cursor: default;
&:hover, &:focus {
background-color: transparent;
}
}
}
}
}
#carousels-orientation {
position: absolute;
top: @carousel-gutter;
right: @carousel-gutter * 2;
li {
.InlineBlock();
width: 8px;
height: 8px;
margin-right: @carousel-gutter;
text-indent: -9999px;
background: url('@{url-theme}/img/carousel-dot-off.png') no-repeat;
&.current {
background: url('@{url-theme}/img/carousel-dot-on.png') no-repeat;
}
}
}
#carousels-window {
clear: both;
position: relative;
width: @width-wrapper;
height: @carousel-height;
margin: @carousel-gutter auto;
.carousel {
position: absolute;
z-index: 100;
height: @carousel-height;
overflow: hidden;
text-align: left;
.panel {
float: left;
margin-right: @carousel-gutter;
.block {
.text {
.hidden-text {
display: none;
}
}
}
}
}
}
.side {
position: absolute;
top: @carousel-controls-height + @carousel-gutter;
z-index: 1000;
.TransparentBackground( #000, .5 );
height: @carousel-height;
width: 100px; // Refreshed dynamically
}
#carousels-side-left {
left: 0;
}
#carousels-side-right {
right: 0;
}
.scroll {
position: absolute;
top: ( ( @carousel-height - @carousel-scroll-height ) / 2 ) + @carousel-controls-height + @carousel-gutter;
z-index: 2000;
width: @carousel-scroll-width;
height: @carousel-scroll-height;
cursor: pointer;
.TransparentBackground( #fff, .6 );
.BorderRadius();
.DropShadow( 4px, 1px, 3px, 2px, .4 );
.arrow {
position: absolute;
width: @carousel-scroll-arrow-width;
height: @carousel-scroll-arrow-height;
top: ( @carousel-scroll-height - @carousel-scroll-arrow-height ) / 2;
right: ( @carousel-scroll-width - @carousel-scroll-arrow-width ) / 2;
background: url('@{url-theme}/img/carousel-arrow-left-off.png') no-repeat;
}
&:hover .arrow, &:focus .arrow {
background: url('@{url-theme}/img/carousel-arrow-left-on.png') no-repeat;
}
}
#carousels-scroll-left {
left: 100px; // Refreshed dynamically
.DropShadow( -4px, 1px, 3px, 2px, .4 );
}
#carousels-scroll-right {
right: 100px; // Refreshed dynamically
.arrow {
background: url('@{url-theme}/img/carousel-arrow-right-off.png') no-repeat;
}
&:hover .arrow, &:focus .arrow {
background: url('@{url-theme}/img/carousel-arrow-right-on.png') no-repeat;
}
}
}
}
.no-js #carousels {
text-align: center;
#carousels-window {
width: @width-wrapper;
margin: 0 auto;
text-align: left;
}
.panel {
margin: 20px 0;
}
}
.lt-ie9 {
.js .home #carousels .scroll {
background: url("@{url-theme}/img/bg-ie-transparent-white.png");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment