0

I have a Wordpress site that on 'content.single.php' (where all single posts are pieced together) My theme puts the featured-image then the content ( and then a back/next nav at the bottom).

html

<article id="post-<?php the_ID(); ?>"<?php post_class('col-md-12'); ?>>
<div class="container">

    <?php
        $thumb = get_post_thumbnail_id();
        $img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
        $image = aq_resize( $img_url, 1200, 720, true ); //resize & crop the image
    ?>

    <?php if($image) : ?>
    <img class="img-responsive singlepic" src="<?php echo $image ?>"/>
    <?php endif; ?> 

<div class="entry-content">
    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header>

    <?php the_content(); ?>
    <?php
        wp_link_pages( array(
            'before' => '<div class="page-links">' . __( 'Pages:', 'web2feel' ),
            'after'  => '</div>',
        ) );
    ?>
</div><!-- .entry-content -->

</div>
</article><!-- #post-## -->

I want to display all the images that are in the post underneath the featured image and in the exact same way.

Is there a function that targets the images in the content of posts?

user3550879
  • 3,389
  • 6
  • 33
  • 62
  • Means you want all the attached image with the post...? – Lakhan Apr 23 '15 at 09:49
  • http://stackoverflow.com/questions/4081520/displaying-all-images-from-a-wordpress-post – Lakhan Apr 23 '15 at 09:57
  • Right now it goes featured-thumbnail (responsive code part makes it large) then post-title then post-content. I want it to go featured-thumnail then each image thats in the content on top of each other (displayed the same way as featured-thumbnail) then post-title then post-content – user3550879 Apr 24 '15 at 01:40
  • You will use jquery to get all your content images and load all the images after the featured image. Also you need to remove all the image from your post content using preg_replace(). – Lakhan Apr 24 '15 at 05:20

2 Answers2

0

Here is a code to get all posts images in a single post as a gallery:

<?php if ( $post->post_type == 'data-design' && $post->post_status == 'publish' ) {
    $attachments = get_posts( array(
        'post_type' => 'attachment',
        'posts_per_page' => -1,
        'post_parent' => $post->ID,
        'exclude'     => get_post_thumbnail_id()
    ) );

    if ( $attachments ) {
        foreach ( $attachments as $attachment ) {
            $class = "post-attachment mime-" . sanitize_title( $attachment->post_mime_type );
            $thumbimg = wp_get_attachment_link( $attachment->ID, 'thumbnail-size', true );
            echo '<li class="' . $class . ' data-design-thumbnail">' . $thumbimg . '</li>';
        }

    }
}
?>
Roshan
  • 16
  • 4
  • 1
    where in my code do i Put it? The best I got was right before the title is inserted but it copies the whole page over and over – user3550879 Apr 24 '15 at 00:24
0

Try with Jquery to do this. It might be resolve your issue.

$(document).ready(function(){
      var img='';
      $('img').each(function(){
          var imgSrc = $(this).attr('src');
          $(this).remove();
          console.log(imgSrc);
          img += '<img src="'+imgSrc+'">';
      });

  $("#imgs").html(img); // this id is targeted div
});

<div id="imgs"></div>
Lakhan
  • 12,328
  • 3
  • 19
  • 28
  • You will also do it like that wise.... http://stackoverflow.com/questions/138313/how-to-extract-img-src-title-and-alt-from-html-using-php – Lakhan Apr 24 '15 at 07:22