我发现并改编了以下代码片段,但有一个问题。效果很好,除了最后一篇帖子。。。由于最后一篇文章没有“上一篇”文章,这似乎会带来问题,并通过在错误的位置添加div来破坏布局。。。
我无法理解哪个部分不起作用。如果我查看了博客的第一篇文章,那么,代码片段运行良好,不会中断。。。如果有人能帮助我理解如果没有上一个或下一个,如何让代码呈现结果,请不要什么都不显示。
<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 } ?>
SO网友:Phll
这应该行得通。关得不好
<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>