1

I am using the 'gamma-gallery' plugin. A little modified, that is.

The gallery is forcing itself above any text that was in the post. Any idea why that is?

Here is the plugins code, if needed:

<?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();
}
?>
2
  • Can we see this live anywhere? I suppose this is some CSS positioning thing, which is both missing (the CSS) and off-topic here. And BTW, above as in in front of (i.e., Z-axis) or before (i.e., Y-axis)?
    – tfrommen
    Commented Sep 28, 2013 at 10:47
  • @tf I meant before - Y-Axis. And it was not a css thing, since the <div> of the gallery was just entered before the text after calling the_content, but the [gallery] tag was behind the text before that.
    – foaly
    Commented Sep 28, 2013 at 11:09

1 Answer 1

2

Your shortcode function callback must return the output, like this:

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

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

    return $html;
}

or you could try the output buffering:

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

    ob_start();

    // your stuff

    $html = ob_get_contents();    
    ob_end_clean();

    return $html;
}
1
  • That was it. The second option worked perfectly. Thanks! :)
    – foaly
    Commented Sep 28, 2013 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.