Forums

Gallery without Images in Post? (1 post)

  1. mikegoodstadt
    Member
    Posted 1 year ago #

    Hi I want to insert a Gallery but want to exclude the images which are inserted alread in the post.
    For example would the following be an option (I am having trouble testing)

    function insert_my_gallery() {
        // Get the post ID
        $iPostID = $post->ID;
        // 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);
    	$sImgList = ' ';
            // Build list array of images attached to post
    	foreach ($arrKeys as $iNum) {
    		// gets the post thumbnail ID
    		$id = get_post_thumbnail_id(get_the_ID());
                    // Build the list
           	        $sImgList .= '' . ', ';
    	}
            // Generate gallery excluding images attached to post.
    	echo do_shortcode("[gallery exclude={$sImgList}]");
    	}
    }

    Can anyone say if this code is valid/well-formed/the best approach???
    I want to avoid plugins and am using a custom child theme of Justin Tadlock's Hybrid theme - could improve on the above using his built-in get_the_image code?
    Many thanks
    Mike

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.