2013-07-19 33 views

回答

0

我想通过不同的灯箱插件自动将rel = lightbox添加到所有img文件类型。这使得它覆盖prettyPhoto(我编码为使用类=“prettyPhoto链接”,而不是一个相对

在function.php

add_filter('the_content', 'chosted_image_attribute'); 

function chosted_image_attribute($content) { 
     global $post; 
     $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i"; 
     $replacement = '<a$1href=$2$3.$4$5 rel="lightbox">'; 
     $content = preg_replace($pattern, $replacement, $content); 
     return $content; 
} 

这是jquery.prettyPhoto.js

顶部
jQuery(function($){ 
    $(document).ready(function(){ 
     $(".prettyphoto-link").prettyPhoto({ 
      animation_speed:'normal', 
      allow_resize: true, 
      keyboard_shortcuts: true, 
      show_title: false, 
      social_tools: false, 
      autoplay_slideshow: false 
     }); 
    }); 
}); 

这可以帮助你从调用PHP代码漂亮的照片,因为有时相对不工作。