[英]Navigation arrows not showing for few images
如果您轉到此處 ,然后單擊圖像,則每個圖像都有“下一個”和“上一個”箭頭,但沒有前兩個圖像。 為什么會這樣呢?
<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>
。
<li>
未創建,因為不滿足以下條件: <?php if($show_next) { ?>
。 這個條件是關於檢查年份是否匹配: if($next_post_year == $current_post_year
。檢查,是否真的需要這個條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.