Pulling attachments from specific post categories
-
I’m having difficulty setting up a homepage gallery which feature images from a specific category of posts.
Basically, what I want is a grid of thumbnails that show random images/attachments from a specific post category that when clicked on either link to the post that they’re in or a gallery of those attachments. Can this be done?
The closest I have come to this is by using this code:
<?php $post_parent = get_post($post->ID, ARRAY_A); $parent = $post_parent['post_parent']; $attachments = get_children( array( 'post_parent' => $post_id, 'posts_per_page' => '18', 'post_type' => 'attachment', 'orderby' => 'rand', 'order' => 'DESC') ); foreach($attachments as $id => $attachment) : echo wp_get_attachment_link($id, 'thumbnail', false); endforeach; ?>
This successfully pulled random images (but not from post categories) and when each thumb is clicked, they just open up the selected attachment on its own.
Really struggling with this. Please help.
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Pulling attachments from specific post categories’ is closed to new replies.