如果您去here,然后单击图像,则每个图像都有“下一个”和“上一个”箭头,但没有前两个图像。为什么会这样?
<nav class="prev-next">
<ul>
<?php
$next_post = get_next_post();
$prev_post = get_previous_post();
$next_post_year = '';
$previous_post_year = '';
$previous_post_media = '';
$next_post_media = '';
if($next_post) {
$next_post_id = ($next_post->ID);
$years = wp_get_post_terms( $next_post_id, 'years', array( 'fields' => 'ids' ) );
$medias = wp_get_post_terms( $next_post_id, 'media', array( 'fields' => 'ids' ) );
$next_post_year = $years[0];
$next_post_media = $medias[0];
}
if($prev_post) {
$previous_post_id = ($prev_post->ID);
$years = wp_get_post_terms( $previous_post_id, 'years', array( 'fields' => 'ids' ) );
$medias = wp_get_post_terms( $previous_post_id, 'media', array( 'fields' => 'ids' ) );
$previous_post_year = $years[0];
$previous_post_media = $medias[0];
}
$show_next = false;
if($next_post_year == $current_post_year && $next_post_media == $current_post_media) {
$show_next = true;
}
$show_prev = false;
if($previous_post_year == $current_post_year && $previous_post_media == $current_post_media) {
$show_prev = true;
}
?>
<?php /*<li class="prev"><?php previous_post('%', '‹ Previous', 'no'); ?></li>
<li class="next"><?php next_post('%' , 'Next ›', 'no'); ?></li>*/ ?>
<?php if($show_next) { ?>
<li class="prev"><?php next_post('%' , '‹ Previous', 'no'); ?></li>
<?php } ?>
<?php if($show_prev) { ?>
<li class="next"><?php previous_post('%', 'Next ›', 'no'); ?></li>
<?php } ?>
</ul>
</nav>
如果您查看未显示箭头的图像的单个图像页面代码,则会发现在这些页面上甚至没有创建下一个<li>
。
答案 0 :(得分:0)
<li>
未创建,因为此条件不满足:<?php if($show_next) { ?>
。
这个条件是关于检查年份是否匹配:if($next_post_year == $current_post_year
。检查,如果您确实需要这种情况。