How to paging without any PageNavi plugins
-
WP-PageNavi is a excellent plugin! But here is just another way to paging without any PageNavi plugins.
First, add this code to functions.php of your theme
function pagenavi( $p = 2 ) { // pages will be show before and after current page if ( is_singular() ) return; // don't show in single page global $wp_query, $paged; $max_page = $wp_query->max_num_pages; if ( $max_page == 1 ) return; // don't show when only one page if ( empty( $paged ) ) $paged = 1; // echo '<span class="pages">Page: ' . $paged . ' of ' . $max_page . ' </span> '; // pages if ( $paged > $p + 1 ) p_link( 1, 'First' ); if ( $paged > $p + 2 ) echo '... '; for( $i = $paged - $p; $i <= $paged + $p; $i++ ) { // Middle pages if ( $i > 0 && $i <= $max_page ) $i == $paged ? print "<span class='page-numbers current'>{$i}</span> " : p_link( $i ); } if ( $paged < $max_page - $p - 1 ) echo '... '; if ( $paged < $max_page - $p ) p_link( $max_page, 'Last' ); } function p_link( $i, $title = '' ) { if ( $title == '' ) $title = "Page {$i}"; echo "<a class='page-numbers' href='", esc_html( get_pagenum_link( $i ) ), "' title='{$title}'>{$i}</a> "; }
Second, add
<?php pagenavi(); ?>
anywhere.( My theme is twenty ten, so I add it to loop.php )At last, add some css code to your style.css file
.page-numbers{margin:10px 2px 0px 2px;padding:1px 8px 1px 8px;text-decoration:none;background:#A3C159;color:#fff;} .page-numbers:hover{background:#009193; color:#FFFFFF;} .current, .current:hover{color:#FFFFFF; background:#009193; border:2px solid #009193;}
If you want to show current page and total page count, remove the comment of line 7.
I hope someone like this tip, and the demo is on: https://www.akasuna.com/
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to paging without any PageNavi plugins’ is closed to new replies.