Wordpress the_content() return only one image from a specific category
<p>I am working on a Wordpress website and I am using a loop to get all the posts that have title and body contain an image.</p>

<p>But the problem is that it returns me all the titles but not all the images. I don't understand why.</p>

<p>Here is the code:</p>

<pre><code>&lt;?php  query_posts('cat=17&amp;order=ASC');
remove_filter('the_content', 'wpautop');

if (have_posts()) : while (have_posts()) : the_post();
    ?&gt;
    &lt;div class="photos"&gt;
        &lt;?php $args = array('post_type' =&gt; 'attachment', 'numberposts' =&gt; 34, 'post_status' =&gt; null, 'post_parent' =&gt; $post-&gt;ID);
        $attachments = get_posts($args);
        if ($attachments) {
            foreach ($attachments as $attachment) {
                ?&gt;
                &lt;a href="&lt;?php echo $attachment-&gt;guid;?&gt;" class="lb_gallery"&gt;&lt;?php the_content();?&gt;&lt;/a&gt;
            &lt;?php
            }
        }?&gt;
        &lt;div class="fotos-desc"&gt;
            &lt;span&gt;&lt;?php the_title();?&gt;&lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;

&lt;?php endwhile; ?&gt;
&lt;?php endif; ?&gt;
</code></pre>

<p>And here is the output on front-end:
<img src="http://i.stack.imgur.com/TS8YR.jpg" alt="enter image description here"></p>

<p>In the above image you can see titles like <em>foto-1</em>, <em>foto-2</em>, <em>foto-3</em> and so on. All these titles are coming through loop but it displays the image for the first one only but all posts are having the image as in the <code>foto-1</code>.</p>
