1

I'm having trouble removing the featured image from gallery.

enter image description here

I removed all kinds of stuff from those 2 files, but seems like I need to add something, not take away. Here are the pastebin's of 2 files:

http://pastebin.com/sBaVzk8y

http://pastebin.com/Ae8TkbAP

4

1 Answer 1

0

Assuming that you are using the standard functionality of the gallery:

[gallery ids = "1,2,3,4,5,6,7,8"]

You can extract the id of the images without having to do a query for attachments of that post with:

preg_match('/\[gallery.*ids=.(.*).\]/', get_the_content(), $ids);

Then make an array of these values:

$ids = explode( ',' $ids[1] );

Eventually check if the id of the featured image exists and get its position( i think that it doesn't exists till you don't place it inside the gallery ):

$pos = array_search( get_post_thumbnail_id( get_the_ID ), $ids);

unset that value:

unset($ids[$pos]);

now you have all the attachments ids, less the one of featured image stored in $ids array.

UPDATE

<?php

    //// GETS OUR IMAGES
    $query_images_args = array(

       'post_type' => 'attachment',
       'post_mime_type' =>'image',
       'post_status' => 'inherit',
       'posts_per_page' => -1,
       'post_parent' => get_the_ID(),
       'exclude' => get_post_thumbnail_id(),
       'orderby' => 'menu_order',
       'order' => 'ASC',

    );

    $images = get_posts( $query_images_args );

    ?>

    <div class="sidebar-item not-in-responsive">

        <script type="text/javascript">

            jQuery(document).ready(function() {

                jQuery('#property-gallery-thumbs').propertyGallery();

            });

        </script>

    <ul id="property-gallery-thumbs">

    <?php

        $i = 1;     
        /// IF WE HAVE MORE THAN JUST ONE IMAGE
        if( $images ) : foreach( $images as $image ) : setup_postdata( $image ); ++$i;

    ?>

            <li class="thumb<?php if($i==1) { echo ' current'; } ?><?php if($i%3 == 0) { echo ' last'; } ?>">

                <span class="hidden full"><?php echo wp_get_attachment_url( $image->ID ); ?></span>
                <span class="hidden main"><?php echo ddTimthumb(wp_get_attachment_url( $image->ID ), 680, 450); ?></span>
                <span class="thumb"><img src="<?php echo ddTimthumb(wp_get_attachment_url( $image->ID ), 76, 76); ?>" alt="<?php the_title() ?>" title="<?php the_title(); ?>" /></span>

            </li>

        <?php endforeach; wp_reset_postdata(); ?>

    </ul>
    <!-- /#property-gallery-thumbs/ -->

</div>

    <?php endif; ?>
14
  • Thanks for comment! Sadly, this didn't work :/ Commented Aug 5, 2013 at 16:35
  • sorry, i'm updating the answer. i hope new solution works
    – iEmanuele
    Commented Aug 5, 2013 at 16:37
  • Sorry for wasting your time mang, didn't manage to get it to work, got : Parse error: syntax error, unexpected 'ids' (T_STRING), expecting ']' in / error. But there's [gallery] nowhere in my theme's code, so I'm not sure if the whole thing you just wasted so much time on applies. Sorry again, upvoted your comment. Commented Aug 5, 2013 at 17:30
  • can you update your gallery template paste on pastebin or make a new one?
    – iEmanuele
    Commented Aug 5, 2013 at 17:48
  • This last update returns in: Fatal error: Call to undefined function wp_resetpostdata() on line 51. Error goes away when I remove wp_resetpostdata. It now hides the thumbnail, but the big image is still there. Commented Aug 5, 2013 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.