Get each images in body in WordPress

I have custom PHP scope in my WordPress theme, like this:

foreach ($myprojects as $post){
        setup_postdata( $post );

        $output .= '<div class="col-xs-6 col-sm-3">';
        $output .= '<div class="portfolio-item">';

        if (has_post_thumbnail($post->ID)) {
            $thumb          = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
            $large_image    = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
            $content        = get_post_field('post_content', $post_id);


            $output .= '<img class="img-responsive" src="'.$thumb[0].'" title="" alt="">';
        }else{
            $output .= '<img class="img-responsive" src="images/work_1.jpg" title="" alt="">';
        }

        $post_id = get_the_title($post->ID);
        $post_name = CFS()->get('project_name', '');

        $output .= '<a class="overlay" rel="shadowbox" href="'.$large_image[0].'">';
        $output .= '<p class="btn-preview">'.$post_id.'</p>';
        $output .= '</a>';

        $output .= '</div>';
        $output .= '</div>';

        $count++;
        $index++;
    }

Yes, it works fine. When I click a tag, open $large_image via prettyPhoto.
But this code for single image. I want to thumbnails stay same, but when click to link, open that multiple image via prettyPhoto. So, imported 2 images in post body and want to show these images.

Read More

In a nutshell, this code:

$large_image    = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');

Must be like this:

$large_image    = wp_get_attachment_image_src( $body($post->ID), 'full');

But I know, this is not correct code. Its pseudo.

How can I fix my problem? Thanks.

Related posts

1 comment

  1. Change your lightbox solution to fancyBox, use data-fancybox-group and a bit of WordPress/PHP knowledge… that’s it!

    foreach ($myprojects as $post){
            setup_postdata( $post );
    
            $output .= '<div class="col-xs-6 col-sm-3">';
            $output .= '<div class="portfolio-item">';
    
            if (has_post_thumbnail($post->ID)) {
                $thumb          = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium');
                $large_image    = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full');
                $content        = get_post_field('post_content', $post_id);
    
    
                $output .= '<img class="img-responsive" src="'.$thumb[0].'" title="" alt="">';
            }else{
                $output .= '<img class="img-responsive" src="images/work_1.jpg" title="" alt="">';
            }
    
            $post_id = get_the_title($post->ID);
            $post_name = CFS()->get('project_name', '');
    
            $output .= '<a class="overlay test fancybox" data-fancybox-group="'.$post->ID.'" href="'.$large_image[0].'">';
            $output .= '<p class="btn-preview">'.$post_id.'</p>';
            $output .= '</a>';
    
            $output .= '</div>';
            $output .= '</div>';
    
            $attached_images = get_attached_media('image', $post->ID);
            foreach($attached_images as $image){
            $large_attached_image = wp_get_attachment_image_src($image->ID,'full');
            if($large_image[0] != $large_attached_image[0]){
            $output .= '<a class="overlay test fancybox" data-fancybox-group="'.$post->ID.'" style="display:none" href="'.$large_attached_image[0].'"></a>';
            }
            }
    
            $count++;
            $index++;
        }
    

Comments are closed.