• I am using the following code to get and display images which are attached to posts that are generated by a form using the Plugin: Formidable.

    <?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 this image to be clickable so that it can be viewed in fullsize.

    <?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).'" />';
    	}
    }
    ?>

    This works as it makes the image clickable, But it also makes all the text in the post clickable. The image links to its correct filepath, but for some reason the text is linking to https://www.link.com/pages/default.aspx/spaced%20out/page.htm. I dont want the text to link to anything, or anywhere. I only want the image to be clickable.

    Can someone please tell me how to edit the above code so that i can have the image be clickable and link to its fullsize image?

  • The topic ‘Clickable image in PhP’ is closed to new replies.