Created
March 15, 2018 20:50
-
-
Save craigsimps/4b830c6715961c2594045f4886f93e13 to your computer and use it in GitHub Desktop.
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 | |
add_action( 'genesis_after_header', __NAMESPACE__ . '\\output_slider' ); | |
/** | |
* Output our slider component after the header. | |
* | |
* @since 1.0.0 | |
*/ | |
function output_slider() { | |
$post_id = get_the_ID(); | |
$image_ids = get_post_meta( $post_id, 'project_header_slider', true ); | |
$slide_urls = []; | |
foreach ( $image_ids as $image_id ) { | |
$slide_urls[] = wp_get_attachment_image_url( $image_id, 'large' ); | |
} | |
// Pass array of slide URLs. | |
wp_localize_script( 'project', 'urls', $slide_urls ); | |
// Add short inline script to initialize Backstretch.js on .slider. | |
wp_add_inline_script( | |
'project', | |
'// <![CDATA[ | |
jQuery(\'.slider\').backstretch(urls, { duration: 6000, fade: 1000 }); | |
// ]]>' | |
); | |
do_action( 'project_before_slider' ); | |
include locate_template( 'views/slider.php' ); | |
do_action( 'project_after_slider' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment