Fix for WordPress, AutoFocus and wide images problem

Update: I uploaded my version of AutoFocus to Google Code.

I’m building a photo blog to show mostly panoramas using WordPress with the AutoFocus plugin. It works fine but I had one issue.

My panoramas are often in 8:1 (width-height) proportions. When I scale the images it means that I get images that are about 100 px high at 800 px width. It makes the images wrap around the div on the first page in the AutoFocus theme.

Wordpress-AutoFocus-Issue

To fix it I installed the Additional image sizes plugin.

Wordpress-AdditionalImageSizes

I configured it to make 800 x 300 images with cropping. I called them 800x300Crop.

Then I added three lines to the function the_post_image_url($size=large) in the functions.php file in AutoFocus. See the code on Google Code.

// Post Attachment image function. Image URL for CSS Background.
function the_post_image_url($size=large) {

        global $post;
        $linkedimgurl = get_post_meta ($post->ID, 'image_url', true);

        if ( $images = get_children(array(
                'post_parent' => get_the_ID(),
                'post_type' => 'attachment',
                'numberposts' => 1,
                'post_mime_type' => 'image',)))
        {
                foreach( $images as $image ) {
                        $attachmenturl=wp_get_attachment_image_src($image->ID, $size);

                        // Added for panoramas
                        // Use the Additional image sizes plugin to generate images that
                        // are 800 x 300 px (cropped) that can be used if the original image
                        // isn't big enough (width or height) when downscaled
                        if($attachmenturl[2] < 300 || $attachmenturl[1] < 800) {
                                the_post_image_url("800x300Crop");
                                return;
                        }

//Keep the rest of the function

It seems to work. Enjoy!

Publicerat av

Ola

Mångsysslande doer & klätterentusiast. Jag driver varumärket Sten & bloggen Klätterbilder. Jag konsultar inom IT & Marknadsföring samt undervisar inom webb på Folkuniversitetet. Jag älskar att fota. /// Doer & climbing enthusiast. I run the climbing brand Sten & the blog Klätterbilder. Consulting with IT & marketing & teaching at Folkuniversitetet. I love to take pictures.