0

I have created a page template that displays the featured image for all posts of a certain custom post type.

It uses a normal loop that is querying that specific custom post type. The thumbnails are being displayed using <?php the_post_thumbnail('project-thumb'); ?>

I now want to use a lightbox to display the rest of the images in the post. I believe that I need to use <?php wp_get_attachment_image_src(); ?>

For some reason I can't quite get my head around it. Can anyone point me in the right direction? Thanks in advance!

1
  • Thanks for joining WPSE. Glad to have you here! If @tosho's answer has solved the issue, please mark it as the correct answer and give him an upvote. This is good protocol and reward for those who spend time to craft answers. :) Commented Sep 15, 2012 at 4:08

1 Answer 1

1

You could use WordPress’ built-in Thickbox script. Just place the following code somewhere before wp_footer();:

add_action( 'wp_footer', 't5_thickbox_jquery' );

function t5_thickbox_jquery()
{
?>
<script>
jQuery( 'a img.size-medium, a img.attachment-thumbnail' )
    .parent()
    .addClass( 'thickbox' )
    .attr( 'rel', 'page' );
</script>
<?php
add_thickbox();
}

See this answer for more details.

3
  • Thanks, toscho! I didn't realize thickbox was build in. I am having another issue and I may be trying to do something that you cannot do. When the link with thumbnail is clicked I want lightbox to show all image attachments in a post, but the function I have is nesting anchor elements within an anchor element which I know is invalid HTML. Here is the function function portfolio_thumbnail_url($pid){ $image_id = get_post_thumbnail_id($pid); $image_url = wp_get_attachment_image_src($image_id,'screen-shot'); return $image_url[0]; }
    – jrelgin
    Commented Aug 20, 2012 at 14:11
  • Sorry @toscho. New to stackexchange. Didn't mean to post above comment as is:-) But, not sure how to write a function that will display all post images in lightbox. Anyway, I will be using thickbox, so thanks again.
    – jrelgin
    Commented Aug 20, 2012 at 14:24
  • @jrelgin If my answer solved your problem tick the little checkmark on the left side so other readers know it is solved. Our list of unanswered questions is already long enough. :)
    – fuxia
    Commented Oct 6, 2012 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.