Forums

wp_get_attachment_image arguments (11 posts)

  1. thegriffon
    Member
    Posted 4 years ago #

    Worked out how to use the [gallery] command with uploaded images, and modified image.php to display how I like, however I still have some unresolved issues:

    wp_get_attachment_image is set to 'medium', not full size as described
    the default (no argument) seems to set the main image to thumbnail size, not full size. seting the argument to 'full', calls the original image, but doesn't display it full size.

    What are the arguments for wp_get_attachment_image, and how do I get the full size image to display without linking to it?

  2. dbirider
    Member
    Posted 4 years ago #

    Bump - I'm having the same problem. I'd like to be able to display the full size image.

  3. ardgedee
    Member
    Posted 4 years ago #

    WordPress is displaying the full size image and using HTML to scale it down to a box 500px wide by (something)px tall.

    $portimg = wp_get_attachment_image( $post->ID, 'full' );
    echo preg_replace('#(width|height)="\d+"#','',$portimg);

    The snippet above strips the WIDTH and HEIGHT attributes from the IMG tag that wp_get_attachment_image() outputs, and displays the image in its natural size. Not my preferred solution, but it works.

  4. malditoweekend
    Member
    Posted 3 years ago #

    Guys I have sort of the same problem but in my case I can´t display the medium size image, I just can controll and display the small thumbnail and large, I can´t find the right code to display the medium size thumb in single.php

    I use this code to display the thumb:

    <?php
    $files = get_children("post_parent=$id&post_type=attachment&post_mime_type=image");
    if($files){
            $keys = array_keys($files);
            $num=$keys[0];
    		$thumb=wp_get_attachment_thumb_url($num);
            print "<div class='tmb'><a href='".get_permalink()."' title=''><img src='$thumb' class='thumbnail' width='130' height='130' alt='' /></a></div>";
    }
    ?>

    And I use this to display the smaller thumb;

    <?php
    $files = get_children("post_parent=$id&post_type=attachment&post_mime_type=image");
    if($files){
            $keys = array_keys($files);
            $num=$keys[0];
            $thumb=wp_get_attachment_thumb_url($num);
            print "<a href='".get_permalink()."' title=''><img src='$thumb' class='thumbnail' width='50' height='50' alt='' /></a>";
    }
    ?>

    But when I try to use the medium size thumb WP resizes the thumb and doesn´t grab the medium size thumb he created it.

    Any advice?
    Real examples:
    Image 1
    Imaeg 2

  5. malditoweekend
    Member
    Posted 3 years ago #

    Solved! thanks anyway.

  6. 007casper
    Member
    Posted 3 years ago #

    malditoweekend how did you get the icon images on your site under quicknotes...

    also I am trying to get the images from the children/subpages pages that links back to the actual subpage... similar to ma.tt's gallery
    any help... really appreciate it

  7. Edde
    Member
    Posted 3 years ago #

    @malditoweekend:

    I'm trying to grab the medium version as well. Since this feature is still sparsely documented - the medium version is not mentioned in the function reference...

    Would you post your solution for all of us?

    Thanks!
    Edde

  8. noyz319
    Member
    Posted 3 years ago #

    malditoweekend, i'm also looking to use the medium sized image in a similar way as you did. It'd be awesome if you could post your solution, as the documentation on this function is almost non-existent.

    Thanks!

  9. hfossli
    Member
    Posted 3 years ago #

    smart tip: do a multifilesearch on all php-files when wondering about a function.. lead me to create this example for you guys ;)

    $size = 150;
    $medium_image = wp_get_attachment_image_src($attachment->ID, array($size, $size), false);

    i haven't checked but you might replace second value (the array) with "small", "medium" etc. or just a single value..

    these three will do your work

    $att_img = wp_get_attachment_image($attachment->ID, array($size, $size), false); // gives <img src="...." />
    $att_src = wp_get_attachment_url($attachment->ID); // gives url to original size
    $att_src_thumb = wp_get_attachment_image_src($attachment->ID, array($size, $size), false); // gives url to givven size..
  10. noelgreen
    Member
    Posted 3 years ago #

    I would still really like someone malditoweekend? to answer how to get the medium sized thumbnail on a page.

  11. zeniph
    Member
    Posted 3 years ago #

    This returns an array of the path(s) to the medium sized image(s).
    Note that 'medium' can also be changed to thumbnail.

    <?php
    $images = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') ); ?>
    
    <?php foreach ($images as $imageId => $image): ?>
    	<?php
    	$wp_medium_image = wp_get_attachment_image_src($imageId,'medium', false);
    	?>
    <img src="<?php echo htmlentities($wp_medium_image[0]); ?>" />

Topic Closed

This topic has been closed to new replies.

About this Topic