i tried this shortcode:
[gallery class="fancybox" link="file" columns="5"]
But the class="fancybox" isn't been added to the a href tag of each image.
How can i add class="fancybox" to each a href tag??
ps: where is the source code of gallery?
|
i tried this shortcode:
But the class="fancybox" isn't been added to the a href tag of each image. How can i add class="fancybox" to each a href tag?? ps: where is the source code of gallery? |
|||
|
You can use javascript/jquery to solve this. When you insert a gallery in a wordpress posts, the whole gallery is wrapped by a div with id like "gallery-1" but also a class that's always "gallery". Also, every item is surrounded by two other "dl" and "dt", with class "gallery-item" and "gallery-icon" respectively. So, you can just use jquery to match every link inside those classes, and add whatever lightbox script you want. If it's fancybox, i think something like this should work:
You can be more specific, matching css classes .gallery .gallery-item .gallery-icon in that order and then the a (for the link). Or use a simple plugin that use the same approach from Viper007Bond, that does clean and nicely, but using colorbox instead. |
|||||
|
Gives all links the same rel attribute, this way the user will be able to slide between the images. |
||||
|
|
function my_get_attachment_link($html) { $postid = get_the_ID(); $html = str_replace('<a', '<a class="fancybox"', $html); return $html; } add_filter('wp_get_attachment_link', 'my_get_attachment_link', 10, 1);– alex Mar 9 '12 at 11:17