最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - PrevNext child navigation for current page modifications?

programmeradmin0浏览0评论

I'm using an answered posted here:

Prev/Next child navigation for current page? by user phife-dawz

The issue: I'm trying to run that inside a function by calling it inside a page template

if( is_page( array( '5145', '7', '8', '25' ) ) ) {
    getPrevNext();
}

The function is placed inside the code snippet plugin and looks like this:

function getPrevNext() {

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

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

    echo '<div class="navigation">';

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

The output I get is only showed with Next link but that also shows only a specific next page regarding the page we are viewing.

发布评论

评论列表(0)

  1. 暂无评论