Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlongren/29323574327395d2c643 to your computer and use it in GitHub Desktop.
Save tlongren/29323574327395d2c643 to your computer and use it in GitHub Desktop.
Soliloquy - Reload Page on Navigation Click and Go to Slider Container
<?php
/**
* Plugin Name: Soliloquy - Reload Page on Navigation Click and Scroll to Slider Container
* Plugin URI: https://longren.io/soliloquy-reload-page-on-navigation-click-and-scroll-to-slider-container
* Version: 1.0
* Author: Tyler Longren
* Author URI: https://longren.io/
* Description: Reloads the entire Page when the next or previous arrows are clicked, or the pager navigation is used. The correct slide is injected into the URL and scrolls to the slider container.
*
* Based on the original plugin from Tim Carr (http://www.n7studios.co.uk). This simply takes the user to the slider after the page reload, good for sliders at the end of posts/pages.
*/
/**
* Reload the entire page with a new slide is requested, showing that slide on the new page request
*
* @param array $data Slider Data
*/
function soliloquy_reload_page_on_navigation_click( $data ) {
global $post;
// Get current post URL
$url = add_query_arg( array( 'sol_slide' => 'soliloquySlideIndexX' ), get_permalink( $post->ID ) );
?>
$(document).on('click', 'a.soliloquy-prev, a.soliloquy-next', function(e) {
e.preventDefault();
var classes = $('li.soliloquy-active-slide', $(this).closest('.soliloquy-wrapper')).attr('class').split(' ');
var containerId = $(".soliloquy-container").prop('id');
var classParts = classes[1].split('-');
var slideIndex = (Number(classParts[2]) - 1);
var url = '<?php echo $url; ?>';
url = url.replace('soliloquySlideIndexX', slideIndex);
url = url + '#' + containerId;
window.location.href = url;
});
$(document).on('click', 'a.soliloquy-pager-link', function(e) {
e.preventDefault();
var url = '<?php echo $url; ?>';
url = url.replace('soliloquySlideIndexX', $(this).data('slide-index'));
window.location.href = url;
});
<?php
}
add_action( 'soliloquy_api_start', 'soliloquy_reload_page_on_navigation_click' );
/**
* Start the slider based on the supplied index
*
* @param array $data Slider Data
* @param int $sliderID Slider ID
* @return array Slider Data
*/
function soliloquy_dynamic_starting_slide( $data, $sliderID ) {
if ( isset( $_GET['sol_slide'] ) ) {
$data['config']['start'] = absint( $_GET['sol_slide'] );
$data['config']['random'] = 0;
}
return $data;
}
add_filter( 'soliloquy_pre_data', 'soliloquy_dynamic_starting_slide', 10, 2 );
/**
* Don't strip double forwardslashes in JS minification, so http[s]:// can be included in our code above without breaking everything
*/
add_filter( 'soliloquy_minify_strip_double_forward_slashes', '__return_false' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment