Thanks alchymyth.
For various reasons-
(Posts opening within a lightbox (hence the need for the class on the <a>
), Using a secondary simplified template (for the lightbox) and also having nav between posts within the lightbox itself required the posts to be called and navigated using post ID instead of permalinks as the permalink URLs point to the post on my themes full single.php template (which I also need)
– I needed to call the previous and next posts by ID and dynamically build my own links with specific classes added directly to the <a>
so that my nav and lightbox would work.
I’ve taken hints from the posts above in this thread, but in the end figured it for my self using get_adjacent_post()
to get post IDs and making my own links – probably a very inefficient hack but it works for me.
Here’s my code – I’m a beginner so it’s fairly rough and I’m sure many of you could find a far better way to do this but it works for me. Now I’ve re-read the posts above I’m fairly positive that I’ve taken a slightly long an abstract approach.
I’ve included a quick method for checking that we’re at the first or last post so I can remove the nav when necessary.
<div class="lightbox-product-nav">
<span id="prev">
<?php if(!get_adjacent_post(false, '', false)) { echo '';
} else
{ $adjacent_post = get_adjacent_post(true,'3,16,17',false) ; ?> <strong>«</strong><a class="fancybox" href="lightbox/?pid=<?php echo $adjacent_post->ID; ?>"> <strong>Previous product:</strong> <?php echo $adjacent_post->post_title;?></a><?php } ?>
</span>
<span id="next">
<?php if(!get_adjacent_post(true, '', true)) { echo '';
} else
{ $adjacent_post = get_adjacent_post(true,'3,16,17',true) ;?>
<a class="fancybox" href="lightbox/?pid=<?php echo $adjacent_post->ID; ?>"><strong>Next product:</strong> <?php echo $adjacent_post->post_title; ?></a> <strong>»</strong><?php } ?>
</span>
</div>