Permalink in attachment page
-
Hi.
I have a custom attachment page where i show one image in its large size, on that page i only display the header/footer and image. But i want to add a link back to the original post.
I have tried with
<?php echo $permalink; ?>but that retrieves the attachment URL, so the question is how to retrieve the post where the image comes from?The code im using to retrive the images in the attachment page is:
<?php if (wp_attachment_is_image($post->id)) { $att_image = wp_get_attachment_image_src( $post->id, "large"); ?> <p> <img src="<?php echo $att_image[0];?>" alt="<?php the_title(); ?>" /> </p> <?php } ?>You could see an example of my attachment page here
http://www.arquitour.com/casa-torres-glr-arquitectos/2010/01/torreshouse-8/
Thanks for your help.
-
And when people come from a category page do you want them to go back to the category page or just to the original post?
For a link back to the original post or (posts if the image is in multiple posts) try this:
<?php if (wp_attachment_is_image($post->id)) { $att_image = wp_get_attachment_image_src( $post->id, "large"); ?> <p> <img src="<?php echo $att_image[0];?>" alt="<?php the_title(); ?>" /> </p> <?php $myposts = get_posts('s='.$att_image[0]); if(!empty($myposts)){ echo '<p>original posts:'; foreach($myposts as $original) : setup_postdata($original); ?> <a href="<?php echo get_permalink($original->ID); ?>"><?php echo $original->post_title; ?></a> <?php endforeach; ?> <?php echo '</p>'; } ?> <?php } ?>keesiemeijer
If people come from a category, search, or anything else i want them to go back to the original post. The images are attached only to one post, but when trying your code it returns a link to my 5 latest posts, but that only works when clicking on an image attached to any of my 5 latest posts.
Any ohter help?
thanks.Ok forget the code I posted before. try this:
<a href="<?php echo get_permalink($post->post_parent) ?>" ><?php echo get_the_title($post->post_parent) ?></a>Thanks keesiemeijer, that worked perfectly!!!!!!!
The topic ‘Permalink in attachment page’ is closed to new replies.