0

When I add this code into my template, i see all of the thumbnails and my links are generating correctly. The only problem is that I'm also seeing the word "Array" in the page next to each thumbnail. Where is this array word coming from and how do i get rid of it? Seems very bizarre.

<?php

$args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' => null,
    'post_parent' => $post->ID
);

$attachments = get_posts($args);
if ($attachments) {
    foreach ($attachments as $attachment) {

        //wp_get_attachment_thumb_url($post->ID);
        /* $img_attr_full = wp_get_attachment_image_src(get_post_thumbnail_id(), 'full');
          $img_attr_thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail'); */

        echo '<li type="1">';
        echo '<a id="' . $post->ID . '" href="' . $img_attr_full[0] . '" class="gallery ' . $media_type . ' ' . $media . '" data-media-type="' . $media . '" target="_blank" rel="gallery">';
        echo wp_get_attachment_image($attachment->ID, 'thumbnail');
        echo '</a></li>';
    }
}
4
  • Is there any more code? You would see "Array" if you attempted to echo a value that was an array instead of a string. The code you have there doesn't look like it should cause that problem. Commented Sep 18, 2011 at 23:32
  • Could you post a part of the source code generated to see where exactly is the Array word appearing? Commented Sep 18, 2011 at 23:37
  • It adds the word array right after the closing </li> tag in the list. ‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌¶‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·Array‌→‌→‌→‌·‌·‌¶‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌·‌· Thats what it looks like in firebug. to output the code above i just echo it out. <?php /* Let's output all of the thumbnails for everything except the videos */ echo $attachments; ?> Commented Sep 18, 2011 at 23:46
  • what do you mean to output the code above? if you're doing something like <ul> <?php echo $attachments;?></ul> then there's your problem Commented Sep 18, 2011 at 23:59

1 Answer 1

1

See this: the implementation of wp_get_attachment_image_src which you are using to fetch the URL for the a element returns an array.

EDIT: echo $attachments; will print out Array. If you remove that you should get better results. In addition, provide a coherent code sample that reflects what is actually in use and producing the error, or you'll cause confusion.

Sign up to request clarification or add additional context in comments.

6 Comments

and he's calling the index 0 which corresponds with the url, the weird thing is he has the assignement of $img_attr_full commented =S
ok, but why is it outputting the word "array" on the page? And how can i get rid of it. its messing the page up.
yeah i had that line commented, i have trying different things to find the cause. I've since uncommented that line and it still does the same thing. :(
then where's getting the $img_attr_full[0] from to create the url?
pretend like it wasn't commented out. i was playing with the code and forgot to uncomment it out before i posted. my apologies.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.