Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I would like to to be able to dynamically land on an specific slide when I arrive on a page with flexslider, based on a query string. As an example I click the link below and it will take me the fourth slide.
like http://example.com/page?startsAt=3"
There is documentation on how to do it on the woothemes site, but would love some guidance on how to do it using the drupal flexslider module.
Flexslider Documentation: https://github.com/woothemes/FlexSlider/issues/562
<script type="text/javascript">
var startAtNum = 0;
<?php if (isset($_GET['startsAt'])){ ?>
startAtNum = <?php echo $_GET['startsAt']; ?>;
<?php } ?>
$(function(){
SyntaxHighlighter.all();
});
$(window).load(function(){
$('.flexslider').flexslider({
startAt: startAtNum
});
});
</script>
Thanks in advance,
Dan
Comments
Comment #1
dandolino CreditAttribution: dandolino commentedComment #2
minorOffense CreditAttribution: minorOffense commentedYou'll need to manupilate the option set before the browser loads it or access the flexslider object on page load and change the settings with javascript.
I would recommend option 1.
Look at the flexslider.module file, has all the Optionset stuff in it.
Comment #3
dandolino CreditAttribution: dandolino commenteddeleted this comment
Comment #4
dandolino CreditAttribution: dandolino commentedHi Matt and Flexslider fans,
I found a way to target a starting slide using a query string. So, if you use http://example.com/yourpage?slide=2 , it should work. This code might not work for multiple optionsets or complex query strings, but im sure other people can help make it more robust. But, it's very simple for my needs. I got the code for getting url variables from css-tricks.com
I just added this code at the very end of this js file /assets/js/flexslider.load.js:
And I added this value into the code below:
startAt:slideNumber
like this:
And if user visits just http://example.com/yourpage, it will just revert to whatever you have set as the default starting slide, or just the first slide.
Comment #5
nickmaine CreditAttribution: nickmaine commented#2 minorOffense is correct, this value needs to be set prior to page load. Altering the value after page load didn't work for me. I used hook_js_alter(), then I'll add code to get information from the path, in my case it will be an image file name. This could also be done in the theme using template_process_flexslider()
This is my first cut, the function could possibly be refined and I will also need to check which flexslider I'm altering, as this inspects sitewide.
Thanks Guys.
Comment #6
amaria CreditAttribution: amaria commentedComment #7
prinds CreditAttribution: prinds commentedif you know the optionset name, then you can do something like: