Viewing 6 replies - 1 through 6 (of 6 total)
  • See the links in this post – under “For Developers”

    WordPress 3.5 “Elvin”

    Thread Starter chevy454

    (@chevy454)

    Doing a view source it looks like after the update it’s not adding the class or other styling attributes from the custom gallery code…I’ve read through the 3.5 info, but I’m not exactly sure what to look for or what I’m missing…anyone have any ideas?

    Here’s a before page: http://www.vintagepowertrain.com/fomoco-test/

    And an after: http://www.vintagepowertrain.com/glide-your-turbo-400/

    Since the update doesn’t touch anything in your specific theme file is it safe to assume the breakage is due to how the new gallery is added to posts versus the old way?

    Thread Starter chevy454

    (@chevy454)

    Prior to my 3.5 upgrade, the below code rendered a page 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

    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.

    This was the code 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 was what was in 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++;
            }
    
        }
    }

    I’ve read 3.5 handles the media attachment ID’s different, which is obviously where I’m encountering the trouble. I’ve tried a few things from the codex and google and either get errors or no change…but I’ve ran across several other people having issues with the 3.5 update in regards to custom galleries.

    Am I overthinking this and simply need to recode for the new shortcode, or does my above code look fixable without too much hassle? I thought the above worked pretty slick, as did my friend who I did the site for…

    Thread Starter chevy454

    (@chevy454)

    I think I’m closer but I’m not sure…now the page returns all of the images contained within the entire media gallery, versus only the ones attached to this specific post’s gallery. It’s formatting it correctly, with the larger image above the content and the thumbnails below the content, but there are only 3 images attached to that post.

    Page url: http://www.vintagepowertrain.com/lkjdkfljdklfj/

    Here’s the code I have now:

    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' => '',
    	'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;
    		preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
    		$attachment_ids = explode(",", $ids[1]);
    		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++;
    		}
    
    	}
    }
    Thread Starter chevy454

    (@chevy454)

    Ok, so I’ve been working most of the day on this…I added the code below, and it’s at least pulling the correct number of images attached to the post, but for some reason it won’t/can’t display them?

    $post_subtitrare = get_post( $post->ID );
        $content = $post_subtitrare->post_content;
        $pattern = get_shortcode_regex();
        preg_match( "/$pattern/s", $content, $match );
        if( isset( $match[2] ) && ( "gallery" == $match[2] ) ) {
            $atts = shortcode_parse_atts( $match[3] );
            $images = isset( $atts['ids'] ) ? explode( ',', $atts['ids'] ) : get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID .'&order=ASC&orderby=menu_order ID' );

    A view source reveals that none of the image info is being fed to the browser, other than the size & placement [size is wrong on top image, Internet Explorer displays the empty images with the red X but FireFox just skips ’em].

    Page url: http://www.vintagepowertrain.com/lkjdkfljdklfj/

    Goodies from my functions.php:

    ////custom gallery
    
    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;
    
        $post_subtitrare = get_post( $post->ID );
        $content = $post_subtitrare->post_content;
        $pattern = get_shortcode_regex();
        preg_match( "/$pattern/s", $content, $match );
        if( isset( $match[2] ) && ( "gallery" == $match[2] ) ) {
            $atts = shortcode_parse_atts( $match[3] );
            $images = isset( $atts['ids'] ) ? explode( ',', $atts['ids'] ) : get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID .'&order=ASC&orderby=menu_order ID' );
    
    		$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++;
    		}
    
    	}
    }

    Thread Starter chevy454

    (@chevy454)

    *bump*

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘3.4–>3.5 and lost gallery hack’ is closed to new replies.