Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save n7studios/475650387fe93d5117de to your computer and use it in GitHub Desktop.
Save n7studios/475650387fe93d5117de to your computer and use it in GitHub Desktop.
Soliloquy - Reload Page on Navigation Click
<?php
/**
* Plugin Name: Soliloquy - Reload Page on Navigation Click
* Plugin URI: http://soliloquywp.com
* Version: 1.0
* Author: Tim Carr
* Author URI: http://www.n7studios.co.uk
* 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.
*/
/**
* 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 classParts = classes[1].split('-');
var slideIndex = (Number(classParts[2]) - 1);
var url = '<?php echo $url; ?>';
url = url.replace('soliloquySlideIndexX', slideIndex);
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' );
@tlongren
Copy link

Thanks for this Tim, exactly what I needed. Had to add some jQuery to your code to go to the slider container after page reload though, as our slideshows are all at the bottom of posts/pages.

So I forked your gist and made a few changes (very few):
https://gist.github.com/tlongren/29323574327395d2c643/revisions

Probably not the best solution (jquery as opposed to WP hooks), but I'm pretty new to Soliloquy. And might as well let the client do the work instead of PHP. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment