不用ngg gallery显示singlepic图片


一个wordpress用了ngg相册,大概有2万张图片,速度慢的不行,关掉了ngg,速度就正常了,于是写了段代码,兼容ngg gallery的singlepic写法,能正常显示图片,网站速度恢复正常。
莫名其妙的插件,怎么能把速度搞这么慢。这段代码可以用作NextGEN Gallery停用后的一个解决方案

<?php
/*
Plugin Name: fcuk ngg gallery
Plugin URI: http://www.juyimeng.com
Description: display pic without ngg
Author: juhui
Version: 1.0
Author URI: http://www.juyimeng.com/
*/
 
function ngg_pic_replacer($content) {
        $search = "@\\

no images were found

@i"; $content= preg_replace_callback( $search, replace_picture , $content,-1); return $content; } function replace_picture($matches) { global $post, $wpdb; $picture_id = $matches['id']; $sql="SELECT * FROM {$wpdb->prefix}ngg_pictures p left join {$wpdb->prefix}ngg_gallery g on p.galleryid=g.gid WHERE p.pid = ". intval( $picture_id ) . " ORDER BY sortorder, pid ASC"; $ngg_image = $wpdb->get_row( $sql ); $append=""; if ($matches['width']) $append.=" width=".$matches['width']; if ($matches['height']) $append.=" height=".$matches['height']; if ($matches['float']) $append.=" align=".$matches['float']; return "<a href=\"/".$ngg_image->path."/".$ngg_image->filename."\"><img class=\"alignnone size-full\" alt=\"image\" ".$append. " src=\"/".$ngg_image->path."/thumbs/thumbs_".$ngg_image->filename."\"/></a>"; } add_filter('the_content', 'ngg_pic_replacer'); add_filter('the_excerpt', 'ngg_pic_replacer'); ?>

部分代码有问题,我是否要发布到wordpress上呢?


发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据