I am inserting an image in a post and I want it to point to the post detail page, not the attachment.
What should I do?
Thanks in advance.
I think I understand what you want, and the problem you are having. I don't have code, but can point you toward some useful resources.
I'm not sure how you are inserting an image into your excerpts on the homepage. My guess is that you are using the More tag in the post editor, inserted after the first paragraph + picture.
However, many templates use the Post Excerpts Function, which will retrieve text from a post, but not include an image. If your template can/does support this, it might be preferable.
These 2 methods (The More Tag vs Post Excepts Function) are described here: http://www.problogdesign.com/how-to/the-2-methods-of-showing-excerpts/
To achive the result you desire, I think you might want to use a feature called Post Thumbnail (dating from WordPress 2.9 and which must be enabled in your template).
If Post Thumbnail is enabled in your template, it is simple to designate a post thumbnail for each post (when you write/edit the post in the WordPress dashboard).
To retrieve that designated Post Thumbnail, your template index page PHP could get the thumbnail image using the function the_post_thumbnail (search if it in the Codex; I don't have privileges to use links here)
You can hyperlink that image using get_post_meta also as described in the Codex.
In the Codex you will find a good example that will demo how to test for the presence of a thumbnail, then use the thumbnail with a hyperlink to the full post. Please search the Codex for get_post_meta look for "Simple Loop Example"
I hope this helps!
When you insert the image, you're given the option to set the image's link. One of the options on the Add an Image screen is Link URL, with three buttons:
Just select "Post URL" and you'll be linking to the post detail page, not the attachment.