How to link the_attachment_link() to the post
-
Hi.
I’m building an image based site. I’m modifying a theme and using the following code (pulled from the codex) to pull the image from each of 2(variable) random posts.
This all works fine. What I am struggling with is making these resulting images link to their relevant post. At the moment, when you click the resulting images they link directly to their raw attachment file.<?php $args = array( 'post_type' => 'attachment', 'numberposts' => 2, 'post_status' => null, 'post_parent' => null, // any parent 'orderby' => 'rand', ); $attachments = get_posts($args); if ($attachments) { foreach ($attachments as $post) { setup_postdata($post); the_attachment_link($post->ID, false); } } ?>
Any help would be greatly appreciated.
TIA
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to link the_attachment_link() to the post’ is closed to new replies.