Javascript 用于Wordpress的带Swipebox的对齐图库

Javascript 用于Wordpress的带Swipebox的对齐图库,javascript,php,jquery,wordpress,gallery,Javascript,Php,Jquery,Wordpress,Gallery,目前,我正试图升级我的自定义模板wordpress与一个新的画廊。我想使用带有swipebox扩展名的 我已经包含了必要的.js和.css文件,我的functions.php如下所示: add_filter( 'post_gallery', 'wpse8170_gallery_shortcode', 10, 2 ); function wpse8170_gallery_shortcode( $output, $attr ) { $post = get_post(); static $insta

目前,我正试图升级我的自定义模板wordpress与一个新的画廊。我想使用带有swipebox扩展名的

我已经包含了必要的.js和.css文件,我的functions.php如下所示:

add_filter( 'post_gallery', 'wpse8170_gallery_shortcode', 10, 2 );
function wpse8170_gallery_shortcode( $output, $attr ) {
$post = get_post();

static $instance = 0;
$instance++;

// override default link settings
if ( empty(  $attr['link'] ) ) {
    $attr['link'] = 'none'; // set your default value here
}

if ( !empty( $attr['ids'] ) ) {
    // 'ids' is explicitly ordered, unless you specify otherwise.
    if ( empty( $attr['orderby'] ) )
        $attr['orderby'] = 'post__in';
    $attr['include'] = $attr['ids'];
}

// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
if ( isset( $attr['orderby'] ) ) {
    $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
    if ( !$attr['orderby'] )
        unset( $attr['orderby'] );
}

extract(shortcode_atts(array(
    'order'      => 'ASC',
    'orderby'    => 'menu_order ID',
    'id'         => $post ? $post->ID : 0,
    'itemtag'    => 'dl',
    'icontag'    => 'dt',
    'captiontag' => 'dd',
    'columns'    => 3,
    'size'       => 'thumbnail',
    'include'    => '',
    'exclude'    => ''
), $attr, 'gallery'));

$id = intval($id);
if ( 'RAND' == $order )
    $orderby = 'none';

if ( !empty($include) ) {
    $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );

    $attachments = array();
    foreach ( $_attachments as $key => $val ) {
        $attachments[$val->ID] = $_attachments[$key];
    }
} elseif ( !empty($exclude) ) {
    $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
} else {
    $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
}

if ( empty($attachments) )
    return '';

if ( is_feed() ) {
    $output = "\n";
    foreach ( $attachments as $att_id => $attachment )
        $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
    return $output;
}

$itemtag = tag_escape($itemtag);
$captiontag = tag_escape($captiontag);
$icontag = tag_escape($icontag);
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) )
    $itemtag = 'dl';
if ( ! isset( $valid_tags[ $captiontag ] ) )
    $captiontag = 'dd';
if ( ! isset( $valid_tags[ $icontag ] ) )
    $icontag = 'dt';

$columns = intval($columns);
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';

$selector = "gallery-{$instance}";

$gallery_style = $gallery_div = '';
if ( apply_filters( 'use_default_gallery_style', true ) )
    $gallery_style = "
    <style type='text/css'>
        #{$selector} {
            margin: auto;
        }
        #{$selector} .gallery-item {
            float: {$float};
            margin-top: 10px;
            text-align: center;
            width: {$itemwidth}%;
        }
        #{$selector} img {
            border: 2px solid #cfcfcf;
        }
        #{$selector} .gallery-caption {
            margin-left: 0;
        }
        /* see gallery_shortcode() in wp-includes/media.php */
    </style>";
$size_class = sanitize_html_class( $size );
$gallery_div = "<div class='swipeboxEx'>";
$output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );

$i = 0;
foreach ( $attachments as $id => $attachment ) {
    if ( ! empty( $attr['link'] ) && 'file' === $attr['link'] )
        $image_output = wp_get_attachment_link( $id, $size, false, false );
    elseif ( ! empty( $attr['link'] ) && 'none' === $attr['link'] )
        $image_output = wp_get_attachment_image( $id, $size, false );
    else
        $image_output = wp_get_attachment_link( $id, $size, true, false );

    $image_meta  = wp_get_attachment_metadata( $id );

    $orientation = '';
    if ( isset( $image_meta['height'], $image_meta['width'] ) )
        $orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';

    $output .= $image_output;
}

$output .= "</div>\n";

return $output; }
add_filter('post_gallery','wpse8170_gallery_shortcode',10,2);
函数wpse8170_gallery_短代码($output,$attr){
$post=get_post();
静态$instance=0;
$instance++;
//覆盖默认链接设置
if(空($attr['link'])){
$attr['link']='none';//在此处设置默认值
}
如果(!empty($attr['id'])){
//除非您另行指定,否则“ID”是显式排序的。
if(空($attr['orderby']))
$attr['orderby']='post_uuuin';
$attr['include']=$attr['id'];
}
//我们信任作者输入,所以至少要确保它看起来像一个有效的orderby语句
如果(isset($attr['orderby'])){
$attr['orderby']=sanitize_sql_orderby($attr['orderby']);
如果(!$attr['orderby'])
未设置($attr['orderby']);
}
提取(短码)附件(数组)(
“订单”=>“ASC”,
'orderby'=>'菜单\u订单ID',
'id'=>$post?$post->id:0,
'itemtag'=>'dl',
'icontag'=>'dt',
'captiontag'=>'dd',
“列”=>3,
“大小”=>“缩略图”,
'包括'=>'',
“排除”=>“
)("画廊"),;
$id=intval($id);
如果('RAND'=$order)
$orderby='none';
如果(!空($include)){
$\u attachments=get\u posts(数组('include'=>$include',post\u status'=>'inherit','post\u type'=>'attachment','post\u mime\u type'=>'image','order'=>$order',orderby'=>$orderby));
$attachments=array();
foreach($\附件为$key=>$val){
$attachments[$val->ID]=$\附件[$key];
}
}elseif(!empty($exclude)){
$attachments=get_children(数组('post_parent'=>$id,'exclude'=>$exclude,'post_status'=>'inherit','post_type'=>'attachment','post_mime_type'=>'image','order'=>$order',orderby'=>$orderby));
}否则{
$attachments=get_children(数组('post_parent'=>$id,'post_status'=>'inherit','post_type'=>'attachments','post_mime_type'=>'image','order'=>$order',orderby'=>$orderby));
}
如果(空($附件))
返回“”;
if(is_feed()){
$output=“\n”;
foreach($att_id=>$attachment形式的附件)
$output.=wp\u get\u attachment\u link($att\u id,$size,true)。“\n”;
返回$output;
}
$itemtag=tag_escape($itemtag);
$captiontag=tag_escape($captiontag);
$icontag=tag_escape($icontag);
$valid_tags=wp_kses_allowed_html('post');
如果(!isset($valid_tags[$itemtag]))
$itemtag='dl';
如果(!isset($valid_tags[$captiontag]))
$captiontag='dd';
如果(!isset($valid_tags[$icontag]))
$icontag='dt';
$columns=intval($columns);
$itemwidth=$columns>0?楼层(100/$columns):100;
$float=is_rtl()?“right”:“left”;
$selector=“gallery-{$instance}”;
$gallery\u style=$gallery\u div='';
如果(应用过滤器('use_default_gallery_style',true))
$gallery_style=”
#{$selector}{
保证金:自动;
}
#{$selector}.gallery项{
浮动:{$float};
边缘顶部:10px;
文本对齐:居中;
宽度:{$itemwidth}%;
}
#{$selector}img{
边框:2个实心#cfcfcf;
}
#{$selector}。库标题{
左边距:0;
}
/*请参见wp includes/media.php中的gallery_shortcode()*/
";
$size\u class=sanitize\u html\u class($size);
$gallery_div=“”;
$output=apply_过滤器('gallery_style',$gallery_style.\n\t\t.$gallery_div);
$i=0;
foreach($id=>$attachment的附件){
如果(!empty($attr['link'])和(&'file'===$attr['link']))
$image\u output=wp\u get\u attachment\u link($id、$size、false、false);
elseif(!empty($attr['link'])和&'none'===$attr['link']))
$image\u output=wp\u get\u attachment\u image($id,$size,false);
其他的
$image\u output=wp\u get\u attachment\u link($id、$size、true、false);
$image\u meta=wp\u get\u attachment\u metadata($id);
$orientation='';
如果(isset($image\u meta['height'],$image\u meta['width']))
$orientation=($image_meta['height']>$image_meta['width'])?“纵向”:“横向”;
$output.=$image\u输出;
}
$output.=“\n”;
返回$output;}
我还在模板的页脚中加入了一些脚本,我认为这可能是正确的,因为图库布局的样式是正确的,但缺少swipebox。用谷歌我试了又试,但找不到解决办法


您可以查看测试页面。

我是Justified Gallery的作者,我为WordPress制作了一个插件,用于从Flickr加载图像,并使用Justified Gallery和Swipebox(如果需要)显示它们

你可以在网上找到它

下载该插件并查看main.php文件,其中有所有使用Arrized gallery显示gallery的简单步骤