导航箭头没有显示几个图像



如果您去这里,然后单击图像,则每个图像都有'next'和``先前''箭头,但不是前两个图像。为什么会发生?

<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('%', '&lsaquo; Previous', 'no'); ?></li>
        <li class="next"><?php next_post('%' , 'Next &rsaquo;', 'no'); ?></li>*/ ?>
        <?php if($show_next) { ?>
        <li class="prev"><?php next_post('%' , '&lsaquo; Previous', 'no'); ?></li>
        <?php } ?>
        <?php if($show_prev) { ?>
        <li class="next"><?php previous_post('%', 'Next &rsaquo;', 'no'); ?></li>
        <?php } ?>      
    </ul>
</nav>

如果您查看未显示箭头的图像的单个图像页面的代码,您会发现下一个和上一个<li>甚至没有在这些页面上创建。

<li>不是创建的,因为此条件不符合:<?php if($show_next) { ?>。这种情况是要检查年是否匹配:if($next_post_year == $current_post_year。检查,如果您真的需要此条件。

最新更新