I think you would have to use jQuery or some js. Isn’t the php already done parsed and rendered by the time the user can mouseover?
Another possibility I think is somehow use CSS background images and switch on :hover
I think the problem with sprites is you would have to create the sprite uniquely for every instance. Here the images already are created and their src rendered it appears by ACF. My vote still for jQuery!
I can use jquery, which is probably best because it’s going to be stuck inside a loop.
<?php
$args = array( 'post_type' => 'team-members' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
I can find plenty of solutions for using jquery to do this but can’t figure out how to incorporate the php get_field names.
@santeven:
Mobile visitors will appreciate the simplicity of a simple sprite, but of course there are many ways to do the same (but proper CSS is the fastest, which is why most site performance tools will point you to using them in exactly this situation).
@htausch,
Your custom loop has what to do with this?
It grabs the contents of the post and displays as many posts as there are of that custom post type. Here’s the full code, I probably should have done that from the beginning:
<?php
$args = array( 'post_type' => 'team-members' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="parent">
<div class="ignore">
<img src="<?php get_field('home_image'); ?>
<div class="text">
<h3><?php the_title(); ?></h3>
</div>
</div>
</div>
<?php endwhile; ?>
Please consult ACF on use of get_field. It is not a WordPress function, but one defined by ACF.
https://wordpress.org/plugins/advanced-custom-fields/
or
http://support.advancedcustomfields.com/
Your loop specifics don’t really matter. The concept you wrote in the topic title and first post are enough. Here’s the concept solution in general:
With PHP in the loop, per post, render both images, or just the first one if there’s only the one. And give them different classes.
With CSS, position the second one absolute covering the first one, and hide the second one.
With jQuery, while mouseover display the second image.
I think the jQuery has to be not in the loop, I usually put it in the footer or it could be right after the endwhile.