ok, so I have it working almost perfectly. But I am having a problem in preventing the thumbnail from showing up when there is no next/previous post; like the next/previous links do.
I other words, when I’m at the last (or first) post of a category, it show the current post thumbnail. Any ides on how to correct this?
test if the $nextPost / $prevPost variables are ‘filled’:
<?php $nextPost = get_next_post(true); if($nextPost) { /*nextthumb*/ } ; ?>
<?php $prevPost = get_previous_post(true); if($prevPost) { /*prevthumb*/ } ; ?>
@alchymyth: thanks! worked like a charm.
@ alchymyth,
I’ve searched high and low for this solution, but could find it anywhere…
Loads of thanks!
This is awesome but for some reason my theme is throwing a Call to undefined function for prev_post_link in the second snippet above. Any ideas why?
I had to make a couple adjustments to the code for the previous post call.
<?php previous_post_link(‘%link »’,’%title’, TRUE); ?>
<?php $prevPost = get_previous_post(true); $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(150,150) ); echo $prevthumbnail; ?>
I’ve put them in bold.
Also, perhaps it’s the modifications I’ve made, but shouldn’t the thumbnails also be linking to the next or previous post?
Cool tip!
Colin this is how I made my thumbnails clickable:
<div id="cooler-nav" class="navigation">
<?php $prevPost = get_previous_post(true);
if($prevPost) {?>
<div class="nav-box previous" style="float:left;">
<?php $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(100,100) );}?>
<?php previous_post_link('%link',"$prevthumbnail %title", TRUE); ?>
</div>
<?php $nextPost = get_next_post(true);
if($nextPost) { ?>
<div class="nav-box next" style="float:right;">
<?php $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(100,100) ); } ?>
<?php next_post_link('%link',"$nextthumbnail %title", TRUE); ?>
</div>
</div><!--#cooler-nav div -->
(I actually put html line breaks before %title but they don’t appear in my code block^)
When I get to the last post i’d like it to show a default image of a cross. Any idea of how to do this?
Thanks
This also works.
<?php $prevPost = get_previous_post(true); $prevThumbnail = get_the_post_thumbnail($prevPost->ID, array(150,150) ); echo $nextthumbnail; ?><?php previous_post_link( '%link', $prevThumbnail ); ?>
using it on the sidebar of for Celebrity is hotter
it’s clickable too.