0

I have a problem with the following code snippet that I found and adapted. Works well, except for the last post...as the last post does not have a "previous" post, this seems to bring up a problem and breaks the layout by adding a div in the wrong place...

I cant undestand what part is not working.If I check the 1st post of the blog, then , the snippet works well, without breaking... if someone could help me understand how to make the code render the results if there is no previous or next, dont show nothing.

<div id="cooler-nav" class="nextprevarea">
<h3 class="commentitle">More Underwater Media</h3>
<?php $prevPost = get_previous_post(false ,'1');
if($prevPost) {?>
<div class="nextprevleft nextprevcommon">
<?php $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(100,100) );?>
<?php previous_post_link('%link',"$prevthumbnail  <p>%title</p>", false , '1'); ?>
    </div>
<?php $nextPost = get_next_post(false ,'1');
if($nextPost) {?>
<div class="nextprevright nextprevcommon">
<?php $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(100,100) ); } ?>
<?php next_post_link('%link',"$nextthumbnail  <p>%title</p>", false , '1'); ?>
</div> 
<?php ?>
</div><!--#cooler-nav div -->
 <?php }  ?>
0

This should work. Wasn't closed well

<div id="cooler-nav" class="navigation">
    <div class="wpb_wrapper">
        <h3>More Underwater Media</h3>
    </div>


<?php $prevPost = get_previous_post(true);
    if($prevPost) {?>
        <div class="nav-box previous">
            <div class="navig_thumb_wrapper">
                <?php $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(100,100) );?>
                <?php previous_post_link('%link',"$prevthumbnail", TRUE); ?>
            </div>
                <?php previous_post_link('%link',"<p>< %title</p>", TRUE); ?>

        </div>
<?php } ?>



<?php  $nextPost = get_next_post(true);
    if($nextPost) {?>
        <div class="nav-box next" style="float:right;">
            <div class="navig_thumb_wrapper">
                <?php $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(100,100) );?>
                <?php next_post_link('%link',"$nextthumbnail", TRUE); ?>
            </div>
                <?php next_post_link('%link',"<p>%title ></p>", TRUE); ?>

        </div>

<?php } ?>

</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.