如题
下面是我使用的部分代码:
<!--获取上下篇日志的链接、标题、特色图像-->
<div class="post-PrevNext">
<?php
$current_category = get_the_category();//获取当前文章所属分类ID
$prev_post = get_previous_post($current_category,'');//与当前文章同分类的上一篇文章
$next_post = get_next_post($current_category,'');//与当前文章同分类的下一篇文章
?>
<!--上一篇-->
<div class="previous_post_link" style="background-image: url(<?php
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($prev_post->ID), 'full');
echo $full_image_url[0];
?>);
background-repeat:round;
cursor: pointer;" onclick="window.location='<?php echo get_permalink( $prev_post->ID ); ?>';
opacity:0.8;">
<!--1,设置特色图片为背景。2、大图像贴合小div、3给div加超级链接-->
<div class="previous_post_link_bg">
<?php if (!empty( $prev_post )): ?>
<div class="single-more">
<div class="single-more-1">上一篇</div>
<a style="color: #FFFFFF;" href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo $prev_post->post_title; ?></a>
<br>
<div class="single-more-1">
<!--创建博文时间:--><a style="color: #a59d9c"><?php the_time( 'Y.m.d' ); ?></a>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!--下一篇博文导航-->
<div class="next_post_link" style="background-image: url(<?php
$full_image_url = wp_get_attachment_image_src( get_post_thumbnail_id($next_post->ID), 'full');
echo $full_image_url[0];?>);
background-repeat:round;
cursor: pointer;" onclick="window.location='<?php echo get_permalink( $next_post->ID ); ?>';">
<div class="previous_post_link_bg">
<?php if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>"><!--获取博文链接-->
<!--获取特色图片-->
</a>
<div class="single-more">
<div class="single-more-1">下一篇</div>
<a style="color: #FFFFFF;" href="<?php echo get_permalink( $next_post->ID ); ?>">
<?php echo $next_post->post_title; ?>
</a>
<br>
<!--创建博文时间:-->
<div class="single-more-1">
<a style="color: #a59d9c"><?php the_time( 'Y.m.d' ); ?></a>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
完整的代码请查看single.php文件:
下载: