WordPress.org

Ready to get started?Download WordPress

Forums

Get images from certain page (1 post)

  1. Dutchman Design
    Member
    Posted 1 year ago #

    I hav ethe following code in my functions.php, to get all images from a page with a given id:

    function getImages($pageID){
    
    $iPostID = $pageID;
    		// Get images for this post
    	    $arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID );
    
    	    // If images exist for this page
    	    if($arrImages) {
    
    	        // Get array keys representing attached image numbers
    	        $arrKeys = array_keys($arrImages);
    
    	 		foreach ($arrKeys as $iNum){
    	 			$sImageUrl = wp_get_attachment_url($iNum);
    				$sImgString = '<img src="' . $sImageUrl . '" alt="Thumbnail Image" title="Thumbnail Image" />';
    
    		        // Print the image
    		        echo $sImgString;
    	 		}
    
    	    }
    	}

    So this function is called from a plugin, and the output is shown in a widget. I keep getting an empty array, although I know for sure the pageID is correct.
    Is there something wrong with my code (obviously...)? Can you help me find a solution?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by Dutchman Design
  • This topic is not resolved
  • WordPress version: 3.4.2