[英]Navigation arrows not showing for few images
If you go here , and click on the images, then each image has 'next' and 'previous' arrows, but not the first two images. 如果您转到此处 ,然后单击图像,则每个图像都有“下一个”和“上一个”箭头,但没有前两个图像。 Why is this happening?
为什么会这样呢?
<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>
If you look at the single image page's code of the images that are not showing the arrows, you will see that the next and previous <li>
are not even being created on those pages. 如果查看未显示箭头的图像的单个图像页面的代码,则会看到在这些页面上甚至没有创建下一个和上一个
<li>
。
<li>
is not created, because this condition doesn't meet: <?php if($show_next) { ?>
. <li>
未创建,因为不满足以下条件: <?php if($show_next) { ?>
。 And this condition is about checking if years are matched: if($next_post_year == $current_post_year
. Check, if you really need this condition. 这个条件是关于检查年份是否匹配:
if($next_post_year == $current_post_year
。检查,是否真的需要这个条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.