图库插件将自身置于文本之上

时间:2013-09-28 作者:foaly

我正在使用“gamma gallery”插件。也就是说,有点修改。

画廊强迫自己超越帖子中的任何文本。知道为什么吗?

以下是插件代码(如果需要):

<?php
/*
Plugin Name:Gamma Gallery
Plugin URI: http://wordpress.org/extend/plugins/gamma-gallery/
Description: A responsive wordpress gallery with montage image arrangement.
Author: ezhil
Version: 1.8
Author URI: http://profiles.wordpress.org/ezhil/
License: GPLv2 or later
*/


define( \'GG_PATH\', content_url().\'/plugins/gamma-gallery\' );

 remove_shortcode(\'gallery\', \'gallery_shortcode\'); // removes the original shortcode
   add_shortcode(\'gallery\', \'gamma_gallery\'); // add your own shortcode

   // loads jquery
function jq_gg_load()
{
wp_enqueue_script(\'jquery\');
}
add_action(\'wp_enqueue_scripts\',\'jq_gg_load\');
    function gamma_gallery($attr) {
    $post = get_post();
//    echo $post;
//        examine($post);

    static $instance = 0;
    $instance++;

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

    // Allow plugins/themes to override the default gallery template.
    $output = apply_filters(\'post_gallery\', \'\', $attr);
    if ( $output != \'\' )
        return $output;

    // 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->ID,
        \'include\'    => \'\',
        \'exclude\'    => \'\'
    ), $attr));

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

//    the_content();
//  echo $text;

?>
<link rel="stylesheet" type="text/css" href="<?php echo GG_PATH;?>/css/style.css"/>
        <script src="<?php echo GG_PATH;?>/js/modernizr.custom.70736.js"></script>
        <noscript><link rel="stylesheet" type="text/css" href="<?php echo GG_PATH;?>/css/noJS.css"/></noscript>
        <!--[if lte IE 7]><style>.main{display:none;} .support-note .note-ie{display:block;}</style><![endif]-->                
                <div class="gamma-container gamma-loading" id="gamma-container">
                    <ul class="gamma-gallery">
                    <?php

        $photos = lc_grab_ids_from_gallery($post);      

    if ($photos) {$ct=0;
        foreach ($photos as $photo) {$ct++;
            $imgdata = get_post($photo);
//            examine($imgdata);
    // data-attachment_url="<?php //echo $imgdata; >"
            $url = get_attachment_link( $imgdata->ID );
?>
<li data-attachment_url="<?php echo $url; ?>">
    <?php //examine($photo); ?>
    <div data-alt="img<?php echo $ct;?>" data-description="<h3><?php 
    $imgdata = get_post($photo);
    if($imgdata->post_excerpt != \'\')
        echo $imgdata->post_excerpt;
    else
        echo $imgdata->post_title;
?> </h3>" data-max-width="3000" data-max-height="2200">
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'xxlarge\');echo $image_attributes[0]; ?>" data-min-width="2000"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'xlarge\');echo $image_attributes[0]; ?>" data-min-width="1300"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'xlarge\');echo $image_attributes[0]; ?>" data-min-width="1000"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'large\');echo $image_attributes[0]; ?>" data-min-width="700"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'large\');echo $image_attributes[0]; ?>" data-min-width="300"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'medium\');echo $image_attributes[0]; ?>" data-min-width="200"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'medium\');echo $image_attributes[0]; ?>" data-min-width="140"></div>
                                <div data-src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'medium\');echo $image_attributes[0]; ?>"></div>
                                <noscript>
                                    <img src="<?php $image_attributes = wp_get_attachment_image_src( $photo, \'medium\');echo $image_attributes[0]; ?>" alt="img<?php echo $ct;?>"/>
                                </noscript>
                            </div>
</li>
<?php 
        }   
    } ?>
</ul>
<div class="gamma-overlay"></div>
</div>
<?php 
    gg_load_scripts();
}
?>

1 个回复
最合适的回答,由SO网友:birgire 整理而成

您的快捷码函数回调必须return 输出如下:

function gamma_gallery( $attr ) {
    $html = \'\';

    // your stuff, where all the output is assigned to the $html variable

    return $html;
}
或者您可以尝试输出缓冲:

function gamma_gallery( $attr ) {
    $html = \'\';

    ob_start();

    // your stuff

    $html = ob_get_contents();    
    ob_end_clean();

    return $html;
}

结束

相关推荐

如何禁用我的主机强制执行的插件(在u-plugins中)?

我的主机制作了两个必需的插件,它们会在mu plugins文件夹下自动更新。有没有一种方法可以通过一些技巧来禁用它们,例如在我的本地插件文件夹下使用一个同名的插件文件夹,或者复制一些函数并使其为空?