Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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. :) –  Brian Fegter Sep 15 '12 at 4:08

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 Aug 20 '12 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 Aug 20 '12 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. :) –  toscho Oct 6 '12 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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