wordpress 实现同一分类上下篇代码
如果有多个分类栏目,可单独建个php文件
引入php文件
<?php require(‘*******.php’);?>
或者<?php get_template_part(‘******.php’);?>
<?php
$current_category=get_the_category();
$prev_post = get_previous_post($current_category,'');
$next_post = get_next_post($current_category,'');
?>
<?php if (!empty( $prev_post )): ?>
<a class="viewpg prev" href="<?php echo get_permalink( $prev_post->ID ); ?>">
<p class="desc hkn500">上一条</p>
<p class="tit ns500">
<?php echo $prev_post->post_title;?>
</p>
<i class="arrartc prev">上一条</i>
</a>
<?php else : ?>
<a class="viewpg prev" title="已经是第一条了">
<i class="arrartc prev">上一条</i>
</a>
<?php endif; ?>
<a class="viewpg list" href="<?php foreach((get_the_category()) as $category){echo get_category_link($category);}?>">产品列表</a>
<?php if (!empty( $next_post )): ?>
<a class="viewpg next" href="<?php echo get_permalink( $next_post->ID ); ?>">
<p class="desc hkn500">下一条</p>
<p class="tit ns500">
<?php echo $next_post->post_title;?>
</p>
<i class="arrartc next">下一条</i>
</a>
<?php else : ?>
<a class="viewpg next" title="已经是最后一条了">
<i class="arrartc next">下一条</i>
</a>
<?php endif; ?>
相关文章