在wordpress网站的简单页面中添加下一页和上一页

时间:2021-07-09 08:06:13

标签: wordpress

嗨,我在一个 WordPress 网站上工作。这基本上是一个基于测验的网站。我想在我的 WordPress 简单页面上添加上一页和下一页按钮。我已经使用了这段代码,但它不起作用`

function get_sibling_link($link) {
    global $post;

    $siblings = get_pages('sort_column=menu_order&child_of='.$post->post_parent.'&parent='.$post->post_parent);

    foreach ($siblings as $key => $sibling){
        if ($post->ID == $sibling->ID){
            $current_id = $key;
        }
    }

    $closest = [ 
        'before' => get_permalink( $siblings[$current_id-1]->ID ),
        'after'  => get_permalink( $siblings[$current_id+1]->ID )
    ];

    if($siblings[$current_id-1]->ID == '' ){
        $closest['before'] = get_permalink( $siblings[count($siblings)-1]->ID );
    }

    if($siblings[$current_id+1]->ID == '' ){
        $closest['after'] = get_permalink( $siblings[0]->ID );
    }

    if ($link == 'before' || $link == 'after') { 
        echo $closest[$link]; 
    } else { 
        return $closest; 
    }
}

`。请指导

0 个答案:

没有答案
相关问题