• I use a template that uses something similar to attachment.php to make pages for thumbnail images (‘linked to page’). The default size seems to be hardcoded by php somewhere to 300px height (which is small compared to my main content well). I can see it when I view source. I want to constrain the width to max. 400px WIDTH so the images will fill the template better. Currently, the user can click the image on the attachment page for full size but it loads as just the jpg on a blank page. I want the image to fill the template by setting the max proportions myself. I can’t see any size values in my php attachment pages and I can’t see where I can set those values from word press. Any ideas? Thnaks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • I’m looking for a similar answer. Rather than have WP limit the height of the image on the “linked to” page I would like to constrain the width or change the height setting to something else. Where do I find the code to change this?

    celebslam

    (@celebslam)

    I’m lookin for the answer to this as well. I should have searched for this before I started a new topic.

    Kafkaesqui

    (@kafkaesqui)

    I should have searched for this before I started a new topic.

    Certainly a good practice for unresolved topics. (I closed your topic and pointed everyone here.)

    Anyway, a solution…

    Best option is to create a template specifically for attachments. WordPress makes this easy, as attachment.php is a default theme template. Here’s a quick way to accomplish what you want:

    1. Copy single.php (from current theme) to attachment.php.

    2. In attachment.php we’ll need to make one big modification, as it will not display the image attachment automatically. Just above:

    <?php the_content(); ?>

    or equivalent (from your theme), here’s what I have in my own attachment.php:

    <?php $image_info = getimagesize($post->guid); ?>
    <img src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" <?php echo $image_info[3]; ?> />

    Description of code:

    First thing, it collects the image’s properties thanks to the PHP function getimagesize(). $post->guid is the record in a post which holds the URL for your attachment.

    In the <p> element it displays the image (by echoing $post->guid) and provides proper alt, title, and the (again thanks to getimagesize()) height and width attributes.

    Feel free to modify the code so it links directly to the image, etc. Since you have a separate template for attachments, you can also change anything else that’s displayed (I don’t list author info or provide comments in mine, for example).

    celebslam

    (@celebslam)

    Thanks. It’s no longer resizing the image, though now I’m getting this message above the picture:

    Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /home/.grandma/nickbillings/celebslam.com/wp-content/themes/green-boqpod-10/attachment.php on line 17

    Warning: getimagesize(https://www.celebslam.com/wp-content/uploads/2006/09/dmxreading2.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/.grandma/nickbillings/celebslam.com/wp-content/themes/green-boqpod-10/attachment.php on line 17

    Kafkaesqui

    (@kafkaesqui)

    You can pull the $image_info line and just use this to display the image:

    <img src="<?php echo $post->guid; ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />

    Not as cool (as it lacks automation of the width and height attributes), but apparently your host restricts PHP functions like getimagesize() from working off of urls.

    celebslam

    (@celebslam)

    Thanks so much. You rock!

    celebslam

    (@celebslam)

    One more small question (I’m sure it’s easy for you PHP Wizards).

    How do I link back to the original post from this neq picture page:

    Check it this picture–there’s no way to indicate this picture came from a story:

    https://www.celebslam.com/hillary-duff-had-it-coming/hilary-duff-stalked-by-russian-maksim-miakovsky/

    Kafkaesqui

    (@kafkaesqui)

    I’m sure it’s easy for you PHP Wizards

    It’s more the WordPress magic we’ll need to wave our wands over…

    Here’s the simplest way to do this; slip it into your attachment.php where you want to link back to the ‘parent’ post (just make sure it’s somewhere in The Loop:

    <a href="<?php echo get_permalink($post->post_parent); ?>"><?php echo get_the_title($post->post_parent); ?></a>

    Now, did Hilary *really* have it coming to her? Don’t make me turn you into a frog!

    Hey, thanks Kafka — this was a perfect fix for me. Very nice to get such a useful response.

    Although this will probably work, in the wordpress version im using, whenever I use linked to page, it always links to a 404 page error.

    Does anyone know why this may happen? I created a post and bumped another post, but I keep finding information on different areas, and trying to piece everything together although i have been unsucessful as of now

    this seems like a great solution but i have a question. can you define the size of the image as well? my images are no longer shrunk down but now appear full size. i’d like to set the size to 400 wide, auto height.

    thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Change default image size on attachment pages’ is closed to new replies.