简体   繁体   中英

Next/previous page link on template receiving a notice

I wanted to have previous and next buttons on certain template pages built in Wordpress. These pages are child pages, so should not go to it's parent or another child.

After reading numerous posts and looking at the code on Wordpress and here. I've come up with the below, but am receiving a ,. ,。

The line is:

$nextID = $pages[$current+1];
    <?php
    $pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order title&sort_order=asc");
    $pages = array();
    foreach ($pagelist as $page) {
        $pages[] += $page->ID;
    }

    $current = array_search(get_the_ID(), $pages);
    $prevID = $pages[$current-1];
    $nextID = $pages[$current+1];
    ?>

    <div class="navigation">
    <?php if (!empty($prevID)) { ?>
        <div class="alignleft">
            <a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous exhibitor</a>
        </div>
        <?php }
        if (!empty($nextID)) { ?>
        <div class="alignright">
            <a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next exhibitor</a>
        </div>
        <?php } ?>
    </div>

How do I remove the error so that when I get to the last page in the child, it disappears?

See if that array element isset or set null :

$nextID = $pages[$current + 1] ?? null;

PHP Manual - Language Operators - Null Coalescing Operator

This is the equivalent to:

$nextID = isset($pages[$current + 1]) ? $pages[$current + 1] : null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM