• Hi,

    after hours of googling I decided to post a new thread. I use onmouseover “galleries” in my loop – and they ar (of course) working just great if there is just one post [ https://petrcibulka.freshflesh.cz/?cat=2, just onmouseover on numbers bellow “current web project” header ]. Images are provided by custom fields.

    The problem is that sript can’t recognize that he needs to generate new “gallery” because there is a new post. Sorry for not using proper words, but I think this is the better way to understand the problem. And here goes the code [ https://petrcibulka.freshflesh.cz/?cat=3 ]:

    <!--script for "gallery"-->
    
    <script type="text/javascript">
    
    	var aryImages = new Array(1);
    	var selIndex = 0;
    
    	aryImages[0] = "<?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
    						{ echo ''. $thumb .''; }
    					?>"
    	aryImages[1] = "<?php $thumb = get_post_meta($post->ID, 'Image1', $single = true); if($thumb !== '')
    						{ echo ''. $thumb .''; }
    					?>"
    
    	for (i=0; i > aryImages.length; i++) {
    		var preload = new Image();
    		preload.src = aryImages[i];
    	}
    
    	function swap(imgIndex, imgTarget) {
    		document[imgTarget].src = aryImages[imgIndex];
    		selIndex = imgIndex;
    	}
    
    </script>
    
    <!-- Code inside the loop, let's say it concerns three posts-->
    
    <table><tr>
    
    <table><tr>
    	<td>
    		<a href="<?php the_permalink(); ?>"><?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
    			{ echo '<img src="'. $thumb .'" alt="dynamic" name="imgDefault" width="380" height="380" border="0" />'; }
    		?></a>
    	</td><td>
    		<span onclick="swap(0, 'imgDefault')" onmouseover="swap(0, 'imgDefault')" class="gal">
    			<?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
    				{ echo '&nbsp;1&nbsp;'; }
    			?>
    		</span>&nbsp;
    		<span onclick="swap(1, 'imgDefault')" onmouseover="swap(1, 'imgDefault')" class="gal">
    			<?php $thumb = get_post_meta($post->ID, 'Image1', $single = true); if($thumb !== '')
    				{ echo '&nbsp;2&nbsp;'; }
    			?>
    		</span>&nbsp;
        </td>
    </tr></table>

    As you can see, “gallery” works just for last post. Any suggestions? I don’t stick to this particular sollution of Javascript array but I don’t want to use any plugin for this and get it work just with custom fields. As far as I know, common onmouseover atribute doesn’t work “distantly” – and I need to change the image which is outside the tag (no matter if anchor or span tag).

    Any help would be very superappreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Arsene

    (@arsene)

    And one more thing: I tried to make “galleries” more unique by ithe_ID() tag and it didn’t work really well. At least I have unique names for images.

    <!--The image which should be changed-->
    
    <?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
    	{ echo '<img src="'. $thumb .'" alt="dynamic" width="380" height="380" name="imgDefault'; }
    ?>
    <?php the_ID(); ?>
    <?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
    	{ echo '" />'; }?>
    ?>
    
    <!--Spans with numbers-->
    
                            <span onclick="swap(0, 'imgDefault<?php the_ID(); ?>')" onmouseover="swap(0, 'imgDefault<?php the_ID(); ?>')" class="gal">
                                <?php $thumb = get_post_meta($post->ID, 'Image0', $single = true); if($thumb !== '')
                                    { echo '&nbsp;1&nbsp;'; }
                                ?>
                            </span>&nbsp;
                            <span onclick="swap(1, 'imgDefault<?php the_ID(); ?>')" onmouseover="swap(1, 'imgDefault<?php the_ID(); ?>')" class="gal">
    							<?php $thumb = get_post_meta($post->ID, 'Image1', $single = true); if($thumb !== '')
                                    { echo '&nbsp;2&nbsp;'; }
                                ?>
    Thread Starter Arsene

    (@arsene)

    Anyone?

    eucopyright

    (@eucopyright)

    Use the raw html plugin, then put your javascript in between the tags…

    [raw]

    <script type=”text/javascript”>
    You Script;
    </script>

    [/raw]

    WARNING =-> You cannot use the visual editor to open the page ever… or it’s screwed and cannot be fixed!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Creating Javascript array in loop’ is closed to new replies.