javascript - 少数图像不显示导航箭头

标签 javascript html css wordpress gallery

如果你去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('%', '&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 .检查,如果你真的需要这个条件。

关于javascript - 少数图像不显示导航箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56087698/

相关文章:

javascript - 使用appendchild将一个div添加到另一个div

javascript - JQuery Post Callback 过滤器选择数据

javascript - Streaming-s3 没有正确上传文件到 aws

javascript - 多个悬停 toggleClass 只工作一次

html - CSS 布局中的 "Whatever is Left"

javascript - 顶级属性不会更新。函数仅在我设置 if function value = to initial top value in javascript 时有效

android - 在平板设备上填充

jquery - iOS Safari Mobile 图像 map - 单击时区域显示框

javascript - 如何在 javascript 中将背景图片正确设置为弹出窗口?

html - 我的选项卡无法正常工作