Quote:
Originally Posted by spudnic072
I am using this code here to get images that have been attached to my posts and to display those attachments in their respective posts on my wordpress blog.
PHP Code:
<?php //Get image genererated from form
$argsThumb = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null
);
$attachments = get_posts($argsThumb);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters('the_title', $attachment->post_title);
echo '<img src="'.wp_get_attachment_url ($attachment->ID, 'thumbnail', false, false).'" />';
}
}
?>
This works great. But I want to be able to click on the image and have the images full size image open, because im am limiting the size that the image is displayed in the post.
To accomplish this I modified the above code to make the image clickable. That also works great. But it is making the entire content of the post clickable. IE: You can click on both the image and the text content in the post. I only want to be able to click on the image.
PHP Code:
<?php //Get image genererated from form
$argsThumb = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null
);
$attachments = get_posts($argsThumb);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters('the_title', $attachment->post_title);
echo '<a href='.wp_get_attachment_url($attachment->ID, 'thumbnail', false, false).'><img src="'.wp_get_attachment_url ($attachment->ID, 'thumbnail', false, false).'" />';
}
}
?>
If anyone can show me how to edit this code so that only the image the code is calling will be clickable thatd be great. Thanks.
|
You need to close your anchor tag, like so:
PHP Code:
<?php //Get image genererated from form
$argsThumb = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null
);
$attachments = get_posts($argsThumb);
if ($attachments) {
foreach ($attachments as $attachment) {
//echo apply_filters('the_title', $attachment->post_title);
echo '<a href='.wp_get_attachment_url($attachment->ID, 'thumbnail', false, false).'><img src="'.wp_get_attachment_url ($attachment->ID, 'thumbnail', false, false).'" /></a>';
}
}
?>
I think that should sort it out for you.
On a related note, HTML validation of the generated page would have pointed this out to you as well, so remember your old pal at
http://validator.w3.org/ when things don't work as expected.