Adding Featured Image to Gallery
  • I use the featured image field for the main image of my posts and for additional images I've styled this plug-in accordingly as thumbnails across the bottom of the main image.

    I would like the prettyPhoto plug-in to work whether there is additional gallery images or only just the one featured image.

    Everything works fine when theres additional images added to it. I can click on the featured image and it loads into the gallery with the rest of them. The problem arises when I have JUST the ONE featured image. It dosen't load correctly into the Lightbox. It simply pops the image up with no styling.

    I need to figure out how to call the JS and CSS of the plug-in even if there no gallery images as part of the post. Is there a way to edit the bit of code from the plug-in that tells it to only load the JS when there image galleries present?


    Heres the code calling my featured image from Single-Post.php:

    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?>
    <div>
    <a href="<?php echo $url; ?>" rel="prettyphoto[group]" style="cursor: pointer;"><?php the_post_thumbnail(); ?></a>
    </div>
    <?php endif; ?>


    Could you please lead me in the right direction so that no matter if theres gallery images or not in the post, this featured image can be opened in a prettyPhoto lightbox as a single image.

    I successfully Enqueued the CSS and the JS for prettyPhoto in my Theme Functions file however I still can't get the easy_image_gallery_js(); function to call properly. HELP! :)

    If you need more info, please let me know. Thanks so much in advance...

    All the best -
  • I resolved this by outputting the Javascript required to load PrettyPhoto on my featured image, see the JS inside easy_image_gallery_js(). Eg:


    jQuery(document).ready(function() {
    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
    social_tools : false,
    show_title : false
    });
    });


    Thanks Andrew!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter