Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.