空の領域

又一个坑爹的神站 大人說:要清爽 要低調

0%

图片Highslide暗箱效果代码

按照资源共享的原则发布了……

原教程来自荒野无灯的博客,这里发现不修改一些地方会导致出错,不过基本方法还是不变的(PS:大师现在也不用wordpress的,其中有个文件也没用了),当然,我不知道大家用原代码会不会出错,所以这里把原代码也放出。

首先,下载Highside.zip

下载完成后把压缩包里的文件上传到主题的根目录,functions.php中加上以下代码:

###############################################################################

# START wp highslide picture code #

###############################################################################

add_filter(‘the_content’, ‘hlHighSlide_replace’, ‘99’);

add_action(‘wp_head’, ‘highslide_head’);

function highslide\_head()

{

$hlHighslide\_wp\_url=get\_bloginfo('template\_url').'/';

$defaults\_javascript =

"\\n\\t<link href='{$hlHighslide\_wp\_url}highslide.css' rel='stylesheet' type='text/css' /> 

    <script type='text/javascript' src='{$hlHighslide\_wp\_url}highslide.js'></script>

<script type='text/javascript'>

hs.showCredits = true;

hs.creditsHref = 'http://www.ihacklog.com/';

    hs.creditsTarget  = '\_self';

hs.graphicsDir = '{$hlHighslide\_wp\_url}graphics/';

hs.align = 'center';

    hs.transitions = \['expand', 'crossfade'\];

    hs.outlineType = 'outer-glow';

    hs.wrapperClassName = 'outer-glow';

    hs.fadeInOut = true;

    hs.dimmingOpacity = 0.3;

    //hs.padToMinWidth = true;

    if (hs.addSlideshow) hs.addSlideshow({

        interval: 5000,

        repeat: false,

        useControls: true,

        fixedControls: 'fit',

        overlayOptions: {

            opacity: .6,

            position: 'bottom center',

            hideOnMouseOut: true

        }

    });

    hs.lang={

loadingText :     '图片加载中...',

loadingTitle :    '正在加载图片',

    closeText :       '关闭',

closeTitle :      '关闭 (Esc)',

    creditsText :     'Powered by <i>荒野无灯</i>',

    creditsTitle :    'http://www.ihacklog.com',

    moveTitle :       '移动图片',

    moveText :        '移动',

    restoreTitle :    '小提示:点击可关闭或拖动. 用左右方向键可查看上一张和下一张-\_-',

    fullExpandTitle : '点击查看原图',

    fullExpandText :  '查看原图'

    };

    hs.registerOverlay({

html: '<div class=\\"closebutton\\" onclick=\\"return hs.close(this)\\" title=\\"Close\\"></div>',

position: 'top right',

fade: 2 // fading the semi-transparent overlay looks bad in IE

    });

    hs.Expander.prototype.onMouseOut = function (sender) {

    sender.close();

    };

    hs.Expander.prototype.onAfterExpand = function (sender) {

    if (!sender.mouseIsOver) sender.close();

     }

     </script>"; 

echo $defaults_javascript;

}

//add onclick event

function add_onclick_replace ($content)

{

$pattern = “/<a(.*?)href=(‘|\“)([^>]*).(bmp|gif|jpeg|jpg|png)(‘|\“)(.*?)>(.*?)<\/a>/i”;

$replacement = ‘<a$1href=$2$3.$4$5 class=”highslide” onclick=”return hs.expand(this)” title=”Click to enlarge(点击查看大图)” $6>$7 ‘;

$content = preg_replace($pattern, $replacement, $content);

return $content;

}

function hlHighSlide_replace($content)

{

    global $post;

    $defaults = array();

    $defaults\['quicktags'\] = 'y';

    $defaults\['href'\] = 'http://www.ihacklog.com/wordpress/wp-content/themes/irresistible/images/logo.png';

    $defaults\['src'\] = 'http://www.ihacklog.com/wordpress/wp-content/themes/irresistible/images/logo.png';

    $defaults\['alt'\] = 'Enter ALT Tag Description';

    $defaults\['title'\] = 'Enter Caption Text';

    $defaults\['thumbid'\] = 'thumb1';

    $defaults\['show\_caption'\] = 'y';

    $defaults\['show\_close'\] = 'y';

    $content=add\_onclick\_replace($content);

    $HSVars = array("SRC", "ALT", "TITLE", "WIDTH", "HEIGHT","THUMBID");

    $HSVals = array($defaults\['href'\], $defaults\['src'\], $defaults\['alt'\], $defaults\['title'\], $defaults\['thumbid'\]);

    preg\_match\_all ('!<img(\[^>\]\*)\[ \]\*\[/\]{1}>!i', $content, $matches);

    $HSStrings = $matches\[0\];

    $HSAttributes = $matches\[1\];

    for ($i = 0; $i < count($HSAttributes); $i++)

    {

        preg\_match\_all('!(src|alt|title|width|height|class)="(\[^"\]\*)"!i',$HSAttributes\[$i\],$matches);

        $HSSetVars = $HSSetVals = array();

        for ($j = 0; $j < count($matches\[1\]); $j++)

        {

            $HSSetVars\[$j\] = strtoupper($matches\[1\]\[$j\]);

            $HSSetVals\[$j\] = $matches\[2\]\[$j\];

        }

    }

        $HSClose = <<<EOT

            <a href="#" onclick="hs.close(this);return false;" class\="highslide-close"  title="关闭"\>Close</a>

EOT;

            $HSCaption = <<<EOT

            <div class\='highslide-caption' id='caption-for-%THUMBID%'\>

            {$HSPrvNextLinks}

            {$HSClose}

            <div style="clear:both"\>%TITLE%</div>

            </div>

EOT;

        $HSCode = <<<EOT

%ALT%{$HSCaption}

EOT;

        for ($j = 0; $j < count($HSVars); $j++)

        {

            $key = array\_search($HSVars\[$j\], $HSSetVars);

            $val = (is\_int($key)) ? $HSSetVals\[$key\] : $HSVals\[$j\];

            if ($HSVars\[$j\] == 'THUMBID')

欢迎关注我的其它发布渠道