Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:14:26+00:00 2026-05-27T12:14:26+00:00

I have 6 images (3 full size and 3 thumbnails) and have loaded each

  • 0

I have 6 images (3 full size and 3 thumbnails) and have loaded each image url into a javascript variable. On my page I have 3 images displaying: one full size and two thumbnails. When the user clicks a thumbnail, I’d like for the full size image to display the full size version of the clicked thumbnail, and the thumbnail to display the thumbnail version of the previous full size image.

I can get this to occur once with the script below. I could also build a giant if/then block to check all cases, but I’m looking for something more elegant. Any ideas?

Thanks!

    function add_image_header(){
    global $post;

    $image_header = get_post_meta( $post->ID, 'image_header', true );
    $image_one_full = get_post_meta( $post->ID, 'image_one_full', true );
    $image_one_cropped = get_post_meta( $post->ID, 'image_one_cropped', true );
    $image_two_full = get_post_meta( $post->ID, 'image_two_full', true );
    $image_two_cropped = get_post_meta( $post->ID, 'image_two_cropped', true );
    $image_three_full = get_post_meta( $post->ID, 'image_three_full', true );
    $image_three_cropped = get_post_meta( $post->ID, 'image_three_cropped', true );

    $page_meta_desc = get_post_meta( $post->ID, 'thesis_description', true );

    if($image_header){
        ?>

            <script type="text/javascript">
                $(document).ready(function(){
                    $("#thumb_one").click(function(){
                        var imageOneFull = "<?php echo $image_one_full;?>";
                        var imageOneCropped = "<?php echo $image_one_cropped;?>";
                        var imageTwoFull = "<?php echo $image_two_full;?>";
                        var imageTwoCropped = "<?php echo $image_two_cropped;?>";
                        var imageThreeFull = "<?php echo $image_three_full;?>";
                        var imageThreeCropped = "<?php echo $image_three_cropped;?>";

                        $('#thumb_one').click($('#main_image').attr("src",imageTwoFull));
                        $('#thumb_one').click($('#thumb_one').attr("src",imageOneCropped));
                    });
                });
            </script>

            <div id="img_header_container">
                <img src="<?php echo $image_one_full;?>" id="main_image"/>
                <img src="<?php echo $image_two_cropped;?>" id="thumb_one"/>
                <img src="<?php echo $image_three_cropped;?>" id="thumb_two"/>
                <div id="heading_text"><h2><?php echo get_the_title($ID) ?></h2><?php echo $page_meta_desc;?></div>
            </div>
        <?php
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:14:27+00:00Added an answer on May 27, 2026 at 12:14 pm

    I give you two solutions.

    1) Use all 3 three thumbnails (which I like more)

    HTML:

    <div id="img_header_container">
                <img src="<?php echo $image_one_full;?>" id="main_image"/>
                <img class="thumb" data-main="?php echo $image_one_full;?>" src="<?php echo $image_one_cropped;?>" />
                <img class="thumb" data-main="?php echo $image_two_full;?>" src="<?php echo $image_two_cropped;?>"/>
                <img class="thumb" data-main="?php echo $image_three_full;?>" src="<?php echo $image_three_cropped;?>"/>
     </div>
    

    Jquery:

      $(document).ready(function(){
                    $(".thumb").click(function(){
                       $('#main_image').attr("src", $(this).data('main'));
                    });
      });
    

    2) Use 2 thumbnails (as requested)

    HTML:

    <div id="img_header_container">
                <img data-thumb="<?php echo $image_one_cropped;?>" src="<?php echo $image_one_full;?>" id="main_image"/>
                <img class="thumb" data-main="?php echo $image_two_full;?>" src="<?php echo $image_two_cropped;?>"/>
                <img class="thumb" data-main="?php echo $image_three_full;?>" src="<?php echo $image_three_cropped;?>"/>
     </div>
    

    Jquery:

      $(document).ready(function(){
                    $(".thumb").click(function(){
                       var Image1Main = $(this).data('main');
                       var Image1Thumb = $(this).attr('src');
    
                       var Image2Main = $('#main_image').attr('src');
                       var Image2Thumb = $('#main_image').data('thumb');
    
                       $('#main_image').attr("src", Image1Main);
                       $('#main_image').data("thumb", Image1Thumb);
    
    
                       $(this).attr("src", Image2Thumb);
                       $(this).data("main", Image2Main);
                    });
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page that will have a full size product image and 4
I have four or five thumbnails next to a full-size image. When I click
I have a page with an image, and two options: Show image full browser
So I have a page with little picture thumbnails on it and one big
I have a thumbnail image you can click to open a full size image
I'm trying to avoid having to create duplicate images (one thumbnail one full size)
I have a div that holds a bunch of thumbnail images. Each image has
I have a directory with fullsize images and thumbnails. The thumbnails are prefixed with
I'm working on some code which fills a GridView full of images that have
I have a directory full of images that I would like to resize to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.