Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I used a tutorial I found for a slick little custom gallery in 3.4, but upon upgrade to 3.5 it no longer works. I'm trying to learn php still and can't seem to get this working again, as I either get errors or nothing at all. Anyway, prior to the upgrade all the user had to do was hit "Add media", upload whatever images he wanted displayed in the post [products, in this case], set the order of the images with the first image being the top/full size image, and then type his description in the text field, and when he hit submit it spit out the above all nicely formatted, like so:

single.php

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x First image attached to post, large size x
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

--------------> Output of content box <--------------

xxxxxxxxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxx
x second image, thumbnail  x  x third image, thumbnail   x
xxxxxxxxxxxxxxxxxxxxxxxxxxxx  xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Here is where I called it in single.php:

<div class="entry-content">
                <div id="top-image"><?php wpo_get_images('large','1','0','large',"$post->ID",'1','feat-img','div','main-thumb'); ?></div>
                <?php the_content(); ?>
                    <div class="outer-element">
                            <?php wpo_get_images('thumbnail','0','1','large',"$post->ID",'1','bot-thumbs','div','inner-element'); ?>
                    </div>
            </div>

And this is from my functions.php:

// Add the ability to use post thumbnails if it isn't already enabled.
// Not required. Use only of you want to have more than the large,
// medium or thumbnail options WP uses by default.

if ( function_exists( 'add_image_size' ) ) add_theme_support( 'post-thumbnails' );

// Add custom thumbnail sizes to your theme. These sizes will be auto-generated
// by the media manager when adding images to it on a new post.
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 't1x1', 145, 200, true );
add_image_size( 't2x1', 307, 200, true );
add_image_size( 't2x2', 307, 417, true );
}

///////////////////////////////////////////////
//
// Start WPOutfitters.com Custom Gallery Function
//
//////////////////////////////////////////////

function wpo_get_images($size = 'thumbnail', $limit = '0', $offset = '0', $big = 'large', $post_id = '$post->ID', $link = '1', $img_class = 'attachment-image', $wrapper = 'div', $wrapper_class = 'attachment-image-wrapper') {
global $post;

$images = get_children( array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );

if ($images) {

    $num_of_images = count($images);

    if ($offset > 0) : $start = $offset--; else : $start = 0; endif;
    if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif;

    $i = 0;
    foreach ($images as $attachment_id => $image) {
        if ($start <= $i and $i < $stop) {
        $img_title = $image->post_title;   // title.
        $img_description = $image->post_content; // description.
        $img_caption = $image->post_excerpt; // caption.
        //$img_page = get_permalink($image->ID); // The link to the attachment page.
        $img_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
        if ($img_alt == '') {
        $img_alt = $img_title;
        }
            if ($big == 'large') {
            $big_array = image_downsize( $image->ID, $big );
            $img_url = $big_array[0]; // large.
            } else {
            $img_url = wp_get_attachment_url($image->ID); // url of the full size image.
            }

        // FIXED to account for non-existant thumb sizes.
        $preview_array = image_downsize( $image->ID, $size );
        if ($preview_array[3] != 'true') {
        $preview_array = image_downsize( $image->ID, 'thumbnail' );
        $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
        $img_width = $preview_array[1];
        $img_height = $preview_array[2];
        } else {
        $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
        $img_width = $preview_array[1];
        $img_height = $preview_array[2];
        }
        // End FIXED to account for non-existant thumb sizes.

        ///////////////////////////////////////////////////////////
        // This is where you'd create your custom image/link/whatever tag using the variables above.
        // This is an example of a basic image tag using this method.
        ?>
        <?php if ($wrapper != '0') : ?>
        <<?php echo $wrapper; ?> class="<?php echo $wrapper_class; ?>">
        <?php endif; ?>
        <?php if ($link == '1') : ?>
        <a href="<?php echo $img_url; ?>" title="<?php echo $img_title; ?>">
        <?php endif; ?>
        <img class="<?php echo $img_class; ?>" src="<?php echo $img_preview; ?>" alt="<?php echo $img_alt; ?>" title="<?php echo $img_title; ?>" />
        <?php if ($link == '1') : ?>
        </a>
        <?php endif; ?>
        <?php if ($img_caption != '') : ?>
        <div class="attachment-caption"><?php echo $img_caption; ?></div>
        <?php endif; ?>
        <?php if ($img_description != '') : ?>
        <div class="attachment-description"><?php echo $img_description; ?></div>
        <?php endif; ?>
        <?php if ($wrapper != '0') : ?>
        </<?php echo $wrapper; ?>>
        <?php endif; ?>
        <?php
        // End custom image tag. Do not edit below here.
        ///////////////////////////////////////////////////////////

        }
        $i++;
    }

}
}

If someone could steer me in the right direction, and maybe even explain what broke and any additional info so I could learn as much as possible would be great!

share|improve this question

2 Answers 2

I guess you were sorta correct, @david.binda, lol!

After a lot of reading, and experimenting, I added the code below to the else statement in my functions file, and it appears to be working as it did before, although the process seems a lot "bulkier" with the new gallery trying to do it's thing.

                $post_content = get_the_content();
                preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
                $array_id = explode(",", $ids[1]);
share|improve this answer
    
With more experimenting I see that it will only work if you upload new images, not ones currently in media library...and you can't see which images are attached to post. Looks like it's still gonna have to be reworked to jive with 3.5+... –  chevy454 Feb 5 '13 at 21:46

Man, it seems that the error is not in any of those codes. I've insertet them (the first one to to single.php and second one to functions.php) to my local WP3.5.1 installation (theme TwentyTwelve), added new post, uploaded 2 images, and everything works as expected - no errror.

The problematic part must be somewhere else. Can you post any of the bunch of erorrs?

share|improve this answer
    
That's just it, I'm not getting any errors, it just doesn't place+style the images as it's supposed to. For example... Page submitted in 3.4: vintagepowertrain.com/fomoco-test Page submitted in 3.5: vintagepowertrain.com/glide-your-turbo-400 It looks to me like the code doesn't grab the images, thus it lets the default gallery do it's thing. This page is for a good friend of mine starting his own business, but he needs it as simple and automated as possible, thus the custom gallery... –  chevy454 Feb 4 '13 at 16:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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