Conditional thumbnail display not working
-
Hello, I have a client that would like for me to have “next” and “previous” arrows on their single.php page, and upon hovering over the arrows, the next or previous post’s thumbnail shows.
So far, the way I have thought to do this is to have an 100×100 arrow image in a 100×100 div; when hovering over the arrow image, it turns 100% transparent and shows the div beneath it, which has a thumbnail as it’s background.
Right now, I have it working on this page: http://ayedom.com/eastman-leather-clothing-aviators-kit-bag/.
But I would like to be able to have a default/generic “thumbnail” image to fallback on since many of his posts do not have featured images set currently. I have tried many methods, and do not know much PHP, and so far I cannot get it to work.
Currently the “right/$nextpost” arrow is working without the conditional code; for now, I am trying to test the “default/fallback” image on the left/$previouspost arrow only.
Here is my code, in my single.php:
<?php if (has_post_thumbnail()) {$previousPost = get_previous_post(true); $previousthumbnail = get_post_thumbnail_id($previousPost->ID);$vspreviousurl = wp_get_attachment_image_src($previousthumbnail, 'thumbnail', true);} else {$vspreviousurl = 'i/arrow_left_big.png';} ?> <?php $nextPost = get_next_post(true); $nextthumbnail = get_post_thumbnail_id($nextPost->ID); $vsnexturl = wp_get_attachment_image_src($nextthumbnail, 'thumbnail', true); ?> <div id="nav-below" class="navigation" style="position:absolute !important;top:300px !important;width:1000px !important;"> <div class="nav-previous" style="display:block;width:100px;height:100px;background:url('<?php echo $vspreviousurl[0]; ?>') 0 0 no-repeat;"><?php previous_post_link('%link', '<img src="i/arrow_left_big.png" class="fadeaway" />') ?></div> <div class="nav-next" style="display:block;width:100px;height:100px;background:url('<?php echo $vsnexturl[0]; ?>') 0 0 no-repeat;"><?php next_post_link('%link', '<img src="i/arrow_right_big.png" class="fadeaway" />') ?></div> </div>Any suggestions would be much appreciated!
The topic ‘Conditional thumbnail display not working’ is closed to new replies.