Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Exclude first featured image from gallery WordPress

  • SOLVED

Hi

I am using Woocommerce and I want to show the Wp "Featurued Image" on the category page... but.. I do not want this image to show in the gallery once you click on that product.

Please see http://www.malloryhills.com/wordpress/boys/ for an example - you will see I am including a colour bar on the image for this page but if you click on the product you will see this colour bar image (featured image) shows as the first one in the gallery.

Is there a way I can tell wordpress to <strong>not</strong> show this first gallery image in the product page?

This is the code woocommerce uses for the gallery section -


<div class="images">

<?php if ( has_post_thumbnail() ) : ?>

<a itemprop="image" href="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>" class="zoom" rel="thumbnails" title="<?php echo get_the_title( get_post_thumbnail_id() ); ?>"><?php echo get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) ) ?></a>

<?php else : ?>

<img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="Placeholder" />

<?php endif; ?>

<?php do_action('woocommerce_product_thumbnails'); ?>

</div>


Many thanks in advance!

Answers (6)

2012-07-16

Manoj Raj answers:

I have a jQuery suggestion

Restore the code as in the start...

Then add this code to your header.php


<script type="text/javascript">
jQuery(document).ready(function() {

jQuery('.thumbnails a.zoom:first').hide();
jQuery('.thumbnails a.zoom:eq(1)').trigger('click');

});
</script>


Manoj Raj comments:

Have you tried my suggestion? I think there are too many additions in your page now... I tried the above code in my console and It worked... If you read the code you can understand what the code is doing... It hides the first thumbnail and then click the second thumbnail to display the image...

Add the code your footer end and let me know..


Jennie Routley comments:

You are genius! Thank you so much, I did not see your solution at first.
Brilliant.

Huge thanks!
Jen


Manoj Raj comments:

Checked your website...Glad that it worked...

2012-07-16

Navjot Singh answers:

Try the solution posted at [[LINK href="http://stackoverflow.com/questions/4337999/wordpress-exclude-the-post-thumbnail-from-gallery-shortcode"]]StackExchange[[/LINK]].


Jennie Routley comments:

Can you tell me how I would go about integrating that into the code I posted above??

Thanks

2012-07-16

Adrian Acevedo answers:

featured picture


<?php
if ( has_post_thumbnail() ){ ?>
<?php $thumbID = get_post_thumbnail_id($post->ID); ?>
<a href="<?php echo wp_get_attachment_url($thumbID); ?>" rel="gallery" title="<?php the_title(); ?>">
<?php the_post_thumbnail(array(290, 290)); ?>
</a>
<?php } ?>



featured picture gallery excluding


<?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 '<ul><li class="list-gallery">';
echo '<a href="' . wp_get_attachment_url($attachment->ID) . '" title="' . esc_attr( $attachment->post_title ) . '">';
echo wp_get_attachment_image( $attachment->ID ,array(60,60) );
echo '</a></li></ul>';
}
}
?>


Jennie Routley comments:

I am so super close with this solution - the only problem is it is giving me 2 of everything - I suppose because of the foreach statement - can you help tell me what to change in the below code to stop it showing the big image twice?
See http://www.malloryhills.com/wordpress/shop/pj-bottoms-cropped/ for a link see what I mean. THANK YOU!

<div class="images">

<?php if ( has_post_thumbnail() ) : ?>


<?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 '<a href="' . wp_get_attachment_url($attachment->ID) . '" class="zoom" rel="thumbnails" title="' . esc_attr( $attachment->post_title ) . '">';

echo wp_get_attachment_image( $attachment->ID ,array(325,325) );

echo '</a>';

}

}

?>



<?php else : ?>



<img src="<?php echo woocommerce_placeholder_img_src(); ?>" alt="Placeholder" />



<?php endif; ?>
<?php do_action('woocommerce_product_thumbnails'); ?>

</div>

2012-07-16

Agus Setiawan answers:

try this plugin : http://wordpress.org/extend/plugins/unattach/


Agus Setiawan comments:

try this plugin : http://wordpress.org/extend/plugins/unattach/ { Allows detaching images and other media from posts, pages and other content types. }

2012-07-16

Martin Pham answers:

try this

function get_product_more_images($offset = 0, $size, $class = '',$num = 10){

global $post;

$args = array(

'order' => 'ASC',

'orderby' => 'menu_order',

'post_type' => 'attachment',

'post_parent' => $post->ID,

'post_mime_type' => 'image',

'post_status' => null,

'numberposts' => $num,

'offset' => $offset,

'exclude' => get_post_thumbnail_id(),

);

$attachments = get_posts($args);

$images = '';

if ($attachments) {

foreach ($attachments as $attachment) {

$images .= wp_get_attachment_image($attachment->ID, $size, false, array('class' => $class) );

}

}

return $images;

}

$offset = 1 : dont get first image

example:

$product_image = get_product_more_images(1, 'medium_thumb', 'class_image', 1);

output

<img src="http://domain.com/image.jpg" class="class_image" />

2012-07-17

Arnav Joy answers:

can you share full code of product display file