WordPress.org

Support

Support » Plugins and Hacks » Get images from certain page

Get images from certain page

  • 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?

  • The topic ‘Get images from certain page’ is closed to new replies.