Skip to content

Instantly share code, notes, and snippets.

@gatespace
Last active February 10, 2017 03:11
Show Gist options
  • Select an option

  • Save gatespace/fb640ab343a2e97fc6bb21f440845430 to your computer and use it in GitHub Desktop.

Select an option

Save gatespace/fb640ab343a2e97fc6bb21f440845430 to your computer and use it in GitHub Desktop.
WordPress ギャラリーショートコードのカスタマイズ(サムネイル+大きい画像+画像が表示されたらGoogleアナリティクスに送信) ref: http://qiita.com/gatespace/items/568a3c601cf762207a87
<div id='gallery-1' class='gallery galleryid-555 gallery-columns-3 gallery-size-thumbnail'>
<div class="gallery-bxslider">
<figure class='slider-item' data-href='/archives/555/canola2'>
<div class='slider-icon landscape'>
<img width="640" height="480" src="http://example.com/wp-content/uploads/2011/01/canola2.jpg" />
</div>
<figcaption class='slider-caption-text slider-caption' id='gallery-1-611'>
caption text.
</figcaption>
</figure>
(.slider-item の繰り返し)
</div>
<div id="bx-pager-1" class="slider-pager">
<a data-slide-index="0" href="#" class="slider-pager-icon"><img width="150" height="150" src="http://example.com/wp-content/uploads/2011/01/canola2-150x150.jpg" class="attachment-thumbnail size-thumbnail" alt="canola" aria-describedby="gallery-1-611" /></a>
(.slider-pager-icon の繰り返し)
</div>
</div>
(function($){
// BxSlider gallery
var gallerybox = $('.gallery');
var gallery, pagerObj, pagerID, slideurl;
if ( gallerybox.length > 0 ) {
gallerybox.each(function(){
gallery = $(this).children('.gallery-bxslider');
pagerObj = $(this).children('.slider-pager');
pagerID = pagerObj.attr('id');
gallery.bxSlider({
pagerCustom: '#' + pagerID,
onSliderLoad: function( currentIndex ) {
slideurl = gallery.children().eq( currentIndex + 1 ).attr( 'data-href' );
console.log(slideurl);
if ( typeof ga == 'function' ) {
ga( 'send', 'pageview', slideurl );
}
},
onSlideBefore: function($slideElement, oldIndex, newIndex) {
slideurl = $slideElement.attr( 'data-href' );
console.log(slideurl);
if ( typeof ga == 'function' ) {
ga( 'send', 'pageview', slideurl );
}
}
});
});
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment