• Hi
    I have activated the post thumbnail function (in WordPress 2.9) and it works fine, but

    when I get my post gallery with the gallery_shortcode i also get the thumbnail as part of my gallery. Is there a way to exclude the thumbnail from the gallery? Something like:
    [gallery exclude"post-thumbnail"]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter magnusc

    (@magnusc)

    Hi esmi
    What am I excluding when I exclude 21? Where can I set all my thumbnail to automaticly have ID=21?

    All my posts will have a gallery with images, and one of these images will be the post thumbnail. I do not want this thumbnail to show up in my slideshow/gallery inside posts so how do I exclude it?

    The pic on the bottom on this page is the thumbnail.
    http://www.formfett.net/tusj-one-handwritten-font

    magnusc,

    You can edit your single template to automatically show the gallery without needing to insert the gallery shortcode manually.
    Open your single.php file and inside the loop, where you want the gallery to be displayed, copy this line of code:

    <?php  $id = get_post_thumbnail_id(get_the_ID()); // gets the post thumbnail ID ?>
    <?php echo do_shortcode("[gallery exclude={$id}]"); // insert the gallery without the thumbnail ?>

    THANKS Cátia, you’re the best.

    same here. Cátia, you’re the greatest.

    You’re a lifesaver Cátia.

    For anyone using get_posts or similar to manually loop through attachments, her solution still works. For example:

    <?php
    	$thumb_id = get_post_thumbnail_id(get_the_ID()); // gets the post thumbnail ID
    
    	$args = array(
    		'order' => 'ASC',
    		'orderby' => 'menu_order',
    		'post_type' => 'attachment',
    		'post_parent' => $post->ID,
    		'post_mime_type' => 'image',
    		'post_status' => null,
    		'numberposts' => -1,
    		'exclude' => $thumb_id
    	);
    
    	$attachments = get_posts($args);
    	if ($attachments) {
    		foreach ($attachments as $attachment) {
    			echo wp_get_attachment_image($attachment->ID, 'medium', false);
    		}
    	}
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Remove Post Thumbnail from the Gallery Shortcode’ is closed to new replies.