Wednesday, August 9, 2017

Wordpress- Post Pagination Modifications (wp_link_pages)

Below code will show Next and Previous Links with the page count in between.
<?php

global $page, $pages;

// This shows the Previous link
wp_link_pages( array( 'before' => '<div class="page-link-next-prev">',
'after' => '', 'previouspagelink' => 'Previous', 'nextpagelink' => '',
'next_or_number' => 'next' ) );

// This shows the page count i.e. "1 of 5"
echo( $page.' of '.count($pages) );

// This shows the Next link
wp_link_pages( array( 'before' => '', 'after' => '</div>', 'previouspagelink' => '',
'nextpagelink' => 'Next', 'next_or_number' => 'next' ) );

?>


For infinite loop prev next, w can use below code- 

global $page, $pages;
                 if(count($pages) > 1){
                    
                  
                    
                echo '<div class="middle-pagination page-link-next-prev">';     
                if($page == 1){
                  
                    ?>
                     <a id="next" href="<?php the_permalink();?><?php echo count($pages);?>/" rel="prev">Prev</a>
                    <?php
                }
              
                wp_link_pages( array( 'before' => '',
                'after' => '', 'previouspagelink' => 'Prev', 'nextpagelink' => '',
                'next_or_number' => 'next' ) );

                // This shows the page count i.e. "1 of 5"
                echo '<span class="m-counts">';
                echo( $page.' of '.count($pages) );
                echo '</span>';

                // This shows the Next link
                wp_link_pages( array( 'before' => '', 'after' => '', 'previouspagelink' => '',
                'nextpagelink' => 'Next', 'next_or_number' => 'next' ) );
              
              
                if($page == count($pages)){
                  
                    ?>
                     <a id="next" href="<?php the_permalink();?>" rel="prev">Next</a>
                    <?php
                }
              
                echo '</div>';
              
                 }

1 comment:


  1. Hello,

    we provide affordable and result-oriented SEO services, please give a chance to serve you.


    Thanks
    Admin: E07.net

    ReplyDelete