I’m making a responsive WordPress folio site (www.jasongilmour.co.uk) and I know very little about WP theme development so got really stuck at some of the PHP. I’m looking to make my site truly responsive by loading different images for different devices but can’t get the right code…
What I have now is getting the full size images from a post for a maximage2 slideshow.
<div id="maximage">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID
);
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, 'full' );
}
}
endwhile; endif; ?>
</div>
I tried to embed it in a <picture>
tag and echo out only the src but when I use wp_get_attachment_image_src
it returns the HTML “ArrayArrayArrayArray
“. I also tried putting echo wp_get_attachment_image( $attachment->ID, 'full', 'src'
but that didn’t change the returned HTML.
I don’t really understand the WP documentation enough to make it work in a… loop or array I think this is called? So that wasn’t much good to me.
This is a pretty important part of my site since I’m using massive images to keep to my design idea and it makes the site very slow before it’s cached.
PS
Although I’ve learned a lot over the past couple of weeks making this, I still don’t really understand what I’m doing with PHP… I’m just a graphic design student.
I might also make the theme open source so if anyone is interested in getting a copy let me know.
I also need to sort an issue with mouse hover menus on tablet devices before I’m happy with it but I don’t understand what I’m doing there either.
Thanks in advance!
That’s beacause that function returns an array according to the source, containing image URL, width and height.
So:
Well it’s not as clean as I hoped but it certainly works, the site is a million times faster now. The Javascript simply comments out the unwanted HTML at certain screen sizes so I can get all the image sizes I need meaning the PHP wasn’t changed.