代码原理也很简单,首先正则判断文章页面中有木有连接到图片的超链接,若有则执行。、
<code>
function if_link2img($content){
/**
* light-highslide by xiaohudie
* coder: http://xiaohudie.net/
* 2013-05-11
*/
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
$pcontent = $post->post_content;if( preg_match_all($pattern, $pcontent, $match) ) {
//load css and js
//若有链接到图片的a,则执行这里的内容.
}
}
add_filter('wp_footer', 'if_link2img');
</code>
function if_link2img($content){
/**
* light-highslide by xiaohudie
* coder: http://xiaohudie.net/
* 2013-05-11
*/
global $post;
$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
$pcontent = $post->post_content;if( preg_match_all($pattern, $pcontent, $match) ) {
//load css and js
//若有链接到图片的a,则执行这里的内容.
}
}
add_filter('wp_footer', 'if_link2img');
</code>
代码可以自己写~~~~