• Resolved dfwgreg

    (@dfwgreg)


    Hi everyone,

    What’s the best way to print the url for an attachment that uses the large format? I’ve tried wp_get_attachment_image_src and it returns an array? This is what I’m using to get the first attachment image.

    <?php
    $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
    if ( ! is_array($attachments) ) continue;
    $count = count($attachments);
    $first_attachment = array_shift($attachments);
    ?>

    Thanks,
    Gregory S.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter dfwgreg

    (@dfwgreg)

    Update: I found a way to display the image.

    <?php echo wp_get_attachment_image( $attachment_id, 'Major story img' );?>

    What I want is to display the url of that attachment, if possible.

    Thanks again,
    Gregory S.

    To display URL of attachment, use this code :

    <?php
    $attachment_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID));
    $display_attachment_url = $attachment_url[0];
    echo $display_attachment_url;
    ?>

    Hopefully it will help. Let me know if it works.

    Thread Starter dfwgreg

    (@dfwgreg)

    I appreciate the help but I found a solution:

    <?php $images = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
    foreach ($images as $imageId => $image);
    $wp_image = wp_get_attachment_image_src($imageId,'Major story img', false);?>

    changing Major story img to whatever size I want and then output the img:
    <?php echo ($wp_image[0]); ?>

    I thank you for the help,
    Gregory S.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to echo the url of an attachment?’ is closed to new replies.