admin管理员组文章数量:1429735
I'm creating a gallery of images using the [gallery]
shortcode and Jetpack's tiled gallery feature. When the user clicks on an image I'm triggering a carousel (Owl Carousel) with carousel.trigger( 'to.owl.carousel', [ item_id, 0 ] )
. The problem that I have is that I need to feed the trigger an index in order to have it jump to the correct item. I've previously done this by using jQuery index()
but that won't work with the tiled gallery because items are nested inside rows.
What I need to do is add a data-index
property to each item in the tiled gallery which I can then have correspond to the index in the carousel. Is there a way in which I can filter the gallery shortcode output in order to add this attribute as it loops through the images?
Off topic but an alternative solution might be leveraging index()
to index the items regardless of their nested row structure, like indexing .item
elements in relation to the parent of parent of parent container. Is that possible?
I'm creating a gallery of images using the [gallery]
shortcode and Jetpack's tiled gallery feature. When the user clicks on an image I'm triggering a carousel (Owl Carousel) with carousel.trigger( 'to.owl.carousel', [ item_id, 0 ] )
. The problem that I have is that I need to feed the trigger an index in order to have it jump to the correct item. I've previously done this by using jQuery index()
but that won't work with the tiled gallery because items are nested inside rows.
What I need to do is add a data-index
property to each item in the tiled gallery which I can then have correspond to the index in the carousel. Is there a way in which I can filter the gallery shortcode output in order to add this attribute as it loops through the images?
Off topic but an alternative solution might be leveraging index()
to index the items regardless of their nested row structure, like indexing .item
elements in relation to the parent of parent of parent container. Is that possible?
1 Answer
Reset to default 0So I've solved the issue by looping through all of the items by class and indexing them with a data attribute.
$( '.tiled-gallery').each(function(){
var i = 0;
$(this).find('.tiled-gallery-item').each(function(){
$(this).attr( 'data-index', i );
i++;
})
})
本文标签: filtersAdd Index to Item in Wordpress Gallery
版权声明:本文标题:filters - Add Index to Item in Wordpress Gallery 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745552922a2663026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论