Skip to main content
deleted 2 characters in body
Source Link
Dejo Dekic
  • 909
  • 1
  • 11
  • 28

Ok buddy add this code to your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override''domain' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}

Then call it in your single.php like so:

<?php my_link_pages(); ?>

Make sure that you add <!--nexpage--> on your Post Edit screen (Select Text NOT Visual)

Ok buddy add this code to your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}

Then call it in your single.php like so:

<?php my_link_pages(); ?>

Make sure that you add <!--nexpage--> on your Post Edit screen (Select Text NOT Visual)

Ok buddy add this code to your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'domain' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}

Then call it in your single.php like so:

<?php my_link_pages(); ?>

Make sure that you add <!--nexpage--> on your Post Edit screen (Select Text NOT Visual)

added 1507 characters in body
Source Link
Dejo Dekic
  • 909
  • 1
  • 11
  • 28
//Will use this function as conditional statement to show or hide our pagination... 
function if_show_posts_nav() {
global $wp_query;
return ( $wp_query->max_num_pages > 1 );
}


//This function is responsible for creating numbered navigation
function my_numbered_nav() {
global $wp_query;

/*We need this here to add numbered Pagination used in paginate_links function  
SEE: https://codex.wordpress.org/Function_Reference/paginate_links
*/
 if ( get_query_var( 'paged' ) ) {
    $paged = absint( get_query_var( 'paged' ) );
    } elseif ( get_query_var( 'page' ) ) {
    $paged = absint( get_query_var( 'page' ) );
    } else {
    $paged = 1;
    }

    //structure of "format" depends on whether we're using pretty permalinks
    if ( get_option('permalink_structure') ) {
    $format = '?paged=%#%';
    } else {
    $format = 'page/%#%/';
    }
    $big = 999999999; // need an unlikely integer
    $base = $format =='?paged=%#%' ? $base = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ) : $base = esc_url( @add_query_arg('paged','%#%') );

    echo paginate_links( array(
    'base' => $base,
    'format' => $format,
    'current' => max( 1, $paged ),
    'total' => $wp_query->max_num_pages,
    'prev_text' => esc_html__( '&lsaquo; Prev', 'domain' ),
    'next_text' => esc_html__( 'Next &rsaquo;', 'domain' ),
    'end_size'  => 1,
    'mid_size'  => 1,
    ) );
}

Then use it like so:

    <?php if ( if_show_posts_nav() ) : ?>
    <div class="navigation">
    <?php my_numbered_nav();?>
    </div><!--/navigation-->
    <?php endif; ?><!--/if_show_posts_nav-->

Note that this code is NOT intended to be used on single.php ,but on index.php.

Now if you really want to divide your single post into pages add this code your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}
//Will use this function as conditional statement to show or hide our pagination... 
function if_show_posts_nav() {
global $wp_query;
return ( $wp_query->max_num_pages > 1 );
}


//This function is responsible for creating numbered navigation
function my_numbered_nav() {
global $wp_query;

/*We need this here to add numbered Pagination used in paginate_links function  
SEE: https://codex.wordpress.org/Function_Reference/paginate_links
*/
 if ( get_query_var( 'paged' ) ) {
    $paged = absint( get_query_var( 'paged' ) );
    } elseif ( get_query_var( 'page' ) ) {
    $paged = absint( get_query_var( 'page' ) );
    } else {
    $paged = 1;
    }

    //structure of "format" depends on whether we're using pretty permalinks
    if ( get_option('permalink_structure') ) {
    $format = '?paged=%#%';
    } else {
    $format = 'page/%#%/';
    }
    $big = 999999999; // need an unlikely integer
    $base = $format =='?paged=%#%' ? $base = str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ) : $base = esc_url( @add_query_arg('paged','%#%') );

    echo paginate_links( array(
    'base' => $base,
    'format' => $format,
    'current' => max( 1, $paged ),
    'total' => $wp_query->max_num_pages,
    'prev_text' => esc_html__( '&lsaquo; Prev', 'domain' ),
    'next_text' => esc_html__( 'Next &rsaquo;', 'domain' ),
    'end_size'  => 1,
    'mid_size'  => 1,
    ) );
}

Then use it like so:

    <?php if ( if_show_posts_nav() ) : ?>
    <div class="navigation">
    <?php my_numbered_nav();?>
    </div><!--/navigation-->
    <?php endif; ?><!--/if_show_posts_nav-->

Note that this code is NOT intended to be used on single.php ,but on index.php.

Now if you really want to divide your single post into pages add this code your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}
//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}
added 1507 characters in body
Source Link
Dejo Dekic
  • 909
  • 1
  • 11
  • 28

Note that this code is NOT intended to be used on single.php ,but on index.php.

Now if you really want to divide your single post into pages add this code your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}

Then call it in your single.php like so:

<?php my_link_pages(); ?>

Make sure that you add <!--nexpage--> on your Post Edit screen (Select Text NOT Visual)

Note that this code is NOT intended to be used on single.php ,but on index.php.

Now if you really want to divide your single post into pages add this code your functions.php

//This function is responsible for splitting posts and pages using <!--nexpage-->
function my_link_pages() {
$paged_page_nav = wp_link_pages(
            array(
            'before' => '<div class="page-navigation"><ul><li class="pages">' . esc_html__( 'Pages:', 'override' ) . '</li>',
            'after' => '</ul></div>',
            'link_before' => '<span>',
            'link_after' => '</span>',
            'echo' => false
            )
         );

//Add "current" and "page_divide" classes to our links
//READ: http://wordpress.stackexchange.com/questions/17421/wp-link-page-wrap-current-page-element
// Now let's wrap the nav inside <li>-elements
$current_class = 'current';
$classes = 'page_divide';
$paged_page_nav = str_replace( '<a', '<li class="'. $classes .'"><a' ,$paged_page_nav );
$paged_page_nav = str_replace( '</span></a>', '</a></li>', $paged_page_nav );
$paged_page_nav = str_replace( '"><span>', '">', $paged_page_nav );
//Add "current" class
$paged_page_nav = str_replace( '<span>', '<li class="'. $current_class .'">', $paged_page_nav );
$paged_page_nav = str_replace( '</span>', '</li>', $paged_page_nav );
echo  $paged_page_nav ;
}

Then call it in your single.php like so:

<?php my_link_pages(); ?>

Make sure that you add <!--nexpage--> on your Post Edit screen (Select Text NOT Visual)

Source Link
Dejo Dekic
  • 909
  • 1
  • 11
  • 28
Loading