Skip to content

Instantly share code, notes, and snippets.

@designbuildtest
Last active August 29, 2015 14:01
Show Gist options
  • Save designbuildtest/e31d3385edbb070ed24f to your computer and use it in GitHub Desktop.
Save designbuildtest/e31d3385edbb070ed24f to your computer and use it in GitHub Desktop.
Use full version of FlexSlider in twentyfourteen theme
<?php
/** Remember to remove the below featuredslider (note custom name) js stuff in functions.js file
*
_window.load( function() {
if ( body.is( '.slider' ) ) {
$( '.featured-content' ).featuredslider( {
selector: '.featured-content-inner > article',
controlsContainer: '.featured-content'
} );
}
} );
*
* /
/**
* In functions.php
*/
if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) {
wp_enqueue_script( 'twentyfourteen-slider', get_template_directory_uri() . '/js/flexslider.js', array( 'jquery' ), '20131205', true );
wp_localize_script( 'twentyfourteen-slider', 'featuredSliderDefaults', array(
'prevText' => __( 'Previous', 'twentyfourteen' ),
'nextText' => __( 'Next', 'twentyfourteen' )
) );
}
/**
* In tweaks.php
*
* If we're on the front page and Featured Content display is set to 'slider', include
* slider initialization script.
*
* If slideshow autoplay is enabled, toggle slideshow value to 'true'.
*/
function twentyfourteen_featured_content_slider() {
if ( is_front_page() && 'slider' == get_theme_mod( 'featured_content_layout' ) ) {
$slider_autoplay = get_theme_mod( 'slider_autoplay' );
if ( $slider_autoplay == 'enabled' ) {
$slideshow = 'true';
}
else {
$slideshow = 'false';
}
?>
<script type="text/javascript" charset="utf-8">
( function( $ ) {
var body = $( 'body' ),
_window = $( window );
_window.load( function() {
if ( body.is( '.slider' ) ) {
$( '.featured-content' ).flexslider( {
selector: '.featured-content-inner > article',
controlsContainer: '.featured-content',
slideshow: <?php echo $slideshow; ?>,
slideshowSpeed: 5000,
animation: 'slide',
smoothHeight: true,
pauseOnHover: true,
video: true,
controlNav: true,
namespace: 'slider-'
} );
}
} );
} )( jQuery );
</script>
<?php }
}
add_action('wp_footer', 'twentyfourteen_featured_content_slider');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment