• I am trying to display the the images in the post on the index.php. This is what I have so far…

    $attachments =& get_children( array(
    		'post_parent' => $theID,
    		'post_type' => 'attachment',
    		'post_mime_type' =>'image'
    	));
    if ($attachments === FALSE) {
    	   echo 'no attachments';
    	} else {
    	    foreach($attachments as $attach) {
    			$attachmenturl=wp_get_attachment_url($attach->ID);
    			echo $attachmenturl;
    			//$attachmentimage=wp_get_attachment_image( $attach->ID, 'thumbnail' );
    	    }
    	}

    The problem is, it only spits out the image of the first post, and echoes ‘no attachment’ for the rest.

    no attachments
    no attachments
    no attachments
    https://localhost:8888/<my site>/wp-content/uploads/2008/10/a.jpg

    My code is all within the Loop.

Viewing 1 replies (of 1 total)
  • Thread Starter generalsalt

    (@generalsalt)

    Okay so I stuck the above code and made it a function and put it in function.php

    function getPostImages(){
    
    	$theID = $post->ID;
    	//echo $theID;
    
    	$attachments =& get_children( array(
    		'post_parent' => $theID,
    		'post_type' => 'attachment',
    		'post_mime_type' =>'image'
    	));
    
    	if ($attachments === FALSE) {
    	   echo 'no attachments';
    	} else {
    	    foreach($attachments as $attach) {
    			$attachmenturl=wp_get_attachment_url($attach->ID);
    			echo $attachmenturl . '<br /><br /><br />';
    			//$attachmentimage=wp_get_attachment_image( $attach->ID, 'thumbnail' );
    	    }
    	}
    }

    I am calling it from within the Loop. It spits out the URL of every pic in the media gallery–for EVERY post.

    Using the ID for each post seems like it should only spit out the photos for that particular post…OK back to the drawing board.

Viewing 1 replies (of 1 total)
  • The topic ‘Need some help with quirky Attachments problem’ is closed to new replies.