• I am looping through all the images in gallery with this:

    add_filter('the_content', 'strip_shortcodes');
    function get_gallery($size = 'thumbnail', $limit = '0', $offset = '0') {
        global $post;
        $images = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
        if ($images) {
            $num_of_images = count($images);
            if ($offset > 0) : $start = $offset--; else : $start = 0; endif;
            if ($limit > 0) : $stop = $limit+$start; else : $stop = $num_of_images; endif;
            $i = 0;
            foreach ($images as $image) {
                if ($start <= $i and $i < $stop) {
                $img_title = $image->post_title;   // title.
                $img_description = $image->post_content; // description.
                $img_caption = $image->post_excerpt; // caption.
                $img_url = wp_get_attachment_url($image->ID); // url of the full size image.
                $preview_array = image_downsize( $image->ID, $size );
                $img_preview = $preview_array[0]; // thumbnail or medium image to use for preview.
                ?>
                <li>
                    <a href="<?php echo $img_url; ?>"><img src="<?php echo $img_preview; ?>" alt="<?php echo $img_caption; ?>" title="<?php echo $img_title; ?>"></a>
                </li>
                <?
                }
                $i++;
            }
        }
    }

    however, I also have a custom “thumbnail” image using this code which uses this plugin(http://wordpress.org/extend/plugins/multiple-post-thumbnails/):

    if (class_exists('MultiPostThumbnails')) {
            new MultiPostThumbnails(array(
            'label' => 'Landing Page Thumb',
            'id' => 'landingpageThumb',
            'post_type' => 'portfolio'
            )
        );
    }

    I looked at plugin code and it looks like it is just pulling a metabox in, like regular featured image box. is there a way to stop the thumbnail from displaying?

    also found this function, but it doesn’t seem to work on my custom gallery output:

    function exclude_thumbnail_from_gallery($null, $attr)
    {
        if (!$thumbnail_ID = get_post_thumbnail_id())
            return $null; // no point carrying on if no thumbnail ID
    
        // temporarily remove the filter, otherwise endless loop!
        remove_filter('post_gallery', 'exclude_thumbnail_from_gallery');
    
        // pop in our excluded thumbnail
        if (!isset($attr['exclude']) || empty($attr['exclude']))
            $attr['exclude'] = array($thumbnail_ID);
        elseif (is_array($attr['exclude']))
            $attr['exclude'][] = $thumbnail_ID;
    
        // now manually invoke the shortcode handler
        $gallery = gallery_shortcode($attr);
    
        // add the filter back
        add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);
    
        // return output to the calling instance of gallery_shortcode()
        return $gallery;
    }
    add_filter('post_gallery', 'exclude_thumbnail_from_gallery', 10, 2);

    also tried this with no luck…

    <?php
        $landingPageThumb = get_post_meta($post->ID, 'landingpageThumb', true);
    
        $args = array('numberposts' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'exclude' =>  array($landingPageThumb),'post_parent' => $post->ID); ?>
                    <?php if ( $photos = get_posts($args) ) : ?>
                        <div class="slides">
                            <?php foreach ( $photos as $photo ) : ?>
                                <div class="slide">
                                    <a href="<?php echo $photo->guid; ?>" class="lightbox" rel="community[<?php echo $post->ID; ?>]"><?php echo wp_get_attachment_image($photo->ID, 'medium'); ?></a>
                                </div>
                            <?php endforeach; ?>
  • The topic ‘exclude custom thumbnail from gallery’ is closed to new replies.