Good afternoon, if you are reading this I am very pleased and I thank you already even if you now cease reading and never respond, perhaps choosing to eat some eggs instead.
I need my posts to have a gallery though I cannot use the gallery shortcode. Trust me I cannot. I need more control over the HTML that is generated and need to add classes to the a tag.
So I have this code within single.php.
<?php if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', ))): ?> <?php foreach( $images as $image ) : ?> <a class="zoom" rel="thumbnails" href="<?php echo wp_get_attachment_url($image->ID); ?>"><img src="<?php echo wp_get_attachment_url($image->ID, 'medium'); ?>"></a> <?php endforeach; ?> <?php else: // No images ?> <?php endif; ?>
Now this code is so very, very nearly doing what is intended with one cruel exception, wp_get_attachment_url is an ignorant fool and chooses to turn a blind eye to 'medium', it instead returns the URL for the original full sized image.
So I am told the solution to this is to use, wp_get_attachment_image_src.
If only it were as straightforward as swapping wp_get_attachment_url with wp_get_attachment_image_src. Oh no it is more complex than that as wp_get_attachment_image_src returns an array and requires some clever coding that is beyond my ability.
When someone says "oh just return an array using wp_get_attachment_image_src" they might as well be saying "oh just pop down the shop and buy me a wholemeal loaf" to a gerbil.
So wise ones, I beg of you, put me out of my misery, help me to find a solution. I just want some code to dish out all the attached images in a medium size. Those images need to link to the original full sized images. It sounds so simple, but I've now been awake for 3 days trying to get this to work. During this time I have soiled my office chair and murdered four people. I just want it to end, you're my only hope.