Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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!

share|improve this answer
    
What I was asking was more a way of overwriting the default link but your answer makes a lot of sense so I'm gonna mark it as good. :) –  ozke Jan 19 '11 at 8:29
add comment

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:

  • None
  • File URL
  • Post URL

Image Upload Form

Just select "Post URL" and you'll be linking to the post detail page, not the attachment.

share|improve this answer
    
I did that and it's pointing to the attachment subpage of the post, not the post. Does it make any sense? –  ozke Jan 13 '11 at 19:03
    
I changed the title so it says what I posted in the text. Is pointing to the attachment page, not the image itself. –  ozke Jan 13 '11 at 19:13
1  
This begs the question of why you want to link to the page a user is already on ... If you're viewing the page with the image, why make the image link to the same page? –  EAMann Jan 13 '11 at 20:43
    
I see what you mean. Basically, I'm showing part of the post in the home page. When someone clicks the image inserted before the "read more" I want them to go to the post single/detail page. Once the person is there the image doesn't need to be a link anymore. –  ozke Jan 14 '11 at 9:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.