Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

otzined on "WP-print - get_attachment shows all images from Media folder"

$
0
0

Hi,

WP version: 3.5.1
WP-print version: 2.52.

For a website I am building I use WP-print. I want to show images from a gallery that's
inside the post. To show the images on the WP-print page I use wp_get_attachment_image, but it shows all the images from the Media folder and not just the attachments from the post.

Current code:

<?php
$gallery = get_children( 'posts_per_page=-1post_type=attachment&post_mime_type=image&post_parent=' . $post->ID );
$attr = array(
    'class' => "attachment-$size wp-post-image",
);
foreach( $gallery as $image ) {
     echo '<a href="' . wp_get_attachment_url($image->ID) . '" rel="gallery-' . get_the_ID() . '">';
     echo wp_get_attachment_image($image->ID, 'thumbnail', false, $attr);
     echo '</a>';
}
?>

Although I am using post_parent=$post->ID it shows all the images from the media folder and not only the attachments from the post.

Hope somebody can help me with this. Struggling with it for a while now.


Viewing all articles
Browse latest Browse all 8245

Trending Articles