WordPress.org

Ready to get started?Download WordPress

Forums

Get the URL of medium thumbnail size (10 posts)

  1. Raisis
    Member
    Posted 3 years ago #

    Hi everybody,

    I try to get the URL of the medium thumbnail size in a loop. I searched and found a lot things. But nothing works :(

    Here are some codes I tried:

    <?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium' );
    $url = $thumb['0']; ?>
    <?php
    $image_id = get_post_thumbnail_id();
    $image_url = wp_get_attachment_image_src($image_id,'medium');
    $image_url = $image_url[0];
    ?>
    <?php
    function wp_get_attachment_medium_url($id){
     $medium_array = image_downsize( $id, 'medium' );
     $medium_path = $medium_array[0];
     return $medium_path;
    }
    ?>

    All of them have an empty result. There is no error.

    Does anyone has an idea what I can do?

    Greetings,
    Raisis

  2. keesiemeijer
    moderator
    Posted 3 years ago #

    This should do it:

    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium');
    $url = $thumb[0];
  3. Raisis
    Member
    Posted 3 years ago #

    No it gives me also an empty result :(

  4. keesiemeijer
    moderator
    Posted 3 years ago #

    Is this in the loop? and do the posts have post thumbnails? Check by using FTP or whatever file management application your host provides to see if the "medium" post thumbnail is in your upload derictory (if it has been genrated by WordPress).

  5. Raisis
    Member
    Posted 3 years ago #

    Yes I placed you code inside the loop and the post have a post thumbnail. There is also a medium post thumbnail in my upload directory.

  6. keesiemeijer
    moderator
    Posted 3 years ago #

    For testing purposes try this:

    $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium');
    echo '<pre>';
    print_r($thumb);
    echo '</pre>';

    this is working on my testserver

  7. wprock
    Member
    Posted 3 years ago #

    try with this function wp_get_attachment_url();

    here is the details http://codex.wordpress.org/Function_Reference/wp_get_attachment_url

    Thx

  8. Raisis
    Member
    Posted 3 years ago #

    @keesiemeijer: That code gives me an array with this information:

    [0] => http://www.link-to-imagefolder.com/teaser-240x135.jpg
    [1] => 240
    [2] => 135
    [3] => 1

    @wprock: I'll try

  9. keesiemeijer
    moderator
    Posted 3 years ago #

    [0] => http://www.link-to-imagefolder.com/teaser-240x135.jpg
    well there is your "medium" image url.

    What do you want to do with it?

  10. Raisis
    Member
    Posted 3 years ago #

    I just like to have the Link without the array around it :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.