I'm creating a website which has the Royal Slider HTML version. I want to use picturefill to load the image optimized for the current resolution viewed. But I have problems getting it to work. It works while I serve the images via a normal WP_Query.
I've read this thread, but that did not help me, anybody an idea?
Thanks, /Paul
<div id="featuredAdv" class="royalSliderAdv rsMinW">
<?php
$args_featured_adv = array(
'posts_per_page' => -1,
'orderby' => 'rand',
'post_type' => 'advertenties',
'meta_key' => 'advertentiepositie',
'meta_value' => 'Featured'
);
$adv_featured = new WP_Query( $args_featured_adv );
if( $adv_featured->have_posts() ): while ( $adv_featured->have_posts() ) : $adv_featured->the_post();
?>
<a href="<?php the_field('link'); ?>" target="_blank" onClick="return recordOutboundLink(this, ['<?php the_title(); ?>', '<?php the_field('link'); ?>']);">
<div class="rsContent">
<?php
$attachment_id_ft = get_field('afbeelding');
$small_ft = wp_get_attachment_image_src( $attachment_id_ft, 'adv-b-small-small' ); // returns an array
$default_ft = wp_get_attachment_image_src( $attachment_id_ft, 'adv-b-small-default' ); // returns an array
$large_ft = wp_get_attachment_image_src( $attachment_id_ft, 'adv-b-small-large' ); // returns an array
?>
<span data-picture data-alt="<?php the_title_attribute( array( 'before' => 'Photoq.nl: ', 'after' => '' ) ); ?>">
<span data-src="<?php echo $default_ft[0]; ?>"></span>
<span data-src="<?php echo $small_ft[0]; ?>" data-media="(min-width: 400px)"></span>
<span data-src="<?php echo $default_ft[0]; ?>" data-media="(min-width: 768px)"></span>
<span data-src="<?php echo $large_ft[0]; ?>" data-media="(min-width: 1200px)"></span>
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
<noscript>
<img src="<?php echo $default_ft[0]; ?>" alt="">
</noscript>
</span>
</div>
</a>
<?php endwhile; endif; wp_reset_query(); ?>
</div> <!-- end #featuredAdv -->
<script>
jQuery(document).ready(function($) {
$('#featuredAdv').royalSlider({
arrowsNav: false,
loop: false,
controlsInside: false,
imageScaleMode: 'none',
imageScalePadding: 0,
arrowsNavAutoHide: false,
autoScaleSlider: true,
autoScaleSliderWidth: 270,
autoScaleSliderHeight: 572,
controlNavigation: 'bullets',
numImagesToPreload: 1,
thumbsFitInViewport: false,
navigateByClick: true,
startSlideId: 0,
autoPlay: false,
transitionType: 'move',
globalCaption: true
});
});
</script>
edit: 28-06 09:40
Got in contact with developer... so he gave some tips. One of them was to make sure picturefill initializes before the slider. With that he means, at least I think, that picturefill.js needs to be loaded before the royalslider files.
Still no luck though. Oh en made a little change in the code due:
<div class="rsIMG">
does not follow the slider syntax.