input license here

[2 TIPs] The easiest way to paginate in WordPress











There are many of you who are not really satisfied with the pagination of the functions available in WordPress. In this article, BKNS will guide you Pagination in WordPress use Plugins and not Plugins. Check it out now!


Guide to Pagination in WordPress

Guide to Pagination in WordPress


1. Guide to Pagination in WordPress Using Plugin


For those who are not connoisseurs of Code, the use of pagination plugin for wordpress Plugin WP-PageNavi is the safe and simple way to apply. The steps are as follows:


Step 1: Load Plugin WP-PageNavi


Step 2: Extract to Plugins folder and activate


Step 3: Configure Plugin to change some display by going to Settings => choose PageNavi


Step 4: Save changed again


Step 5: Appears pagination line in Theme Twentyten. These two lines work Next and Preview posts


<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentyten' ) ); ?></div>

And:


<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentyten' ) ); ?></div>

Step 6: Replace those 2 lines with 1 simple line and finish WordPress pagination Using Plugins:


<?php wp_pagenavi(); ?>

2. Guide to Pagination in WordPress Without Using Plugins


Using the WP-PageNavi Plugin to number pages in wordpress is applied by many of you. However, there are many of you who do not like to install too many Plugins for a WordPress website. Here, BKNS will guide you on how to pagination for category/post wordpress Don't use Plugins. The steps are as follows:


Step 1: Check the theme you are using has the file functions.php or not? If you don't have this file, create more file functions.php in folder Theme using


Step 2: Add the following code to the newly created file:


function page_nav() {

         if( is_singular() )

                     return;

         global $wp_query;

         /** Stop execution if there's only 1 page */

         if( $wp_query->max_num_pages <= 1 )

                     return;

         $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;

         $max   = intval( $wp_query->max_num_pages );

         /**   Add current page to the array */

         if ( $paged >= 1 )

                     $links[] = $paged;

         /**   Add the pages around the current page to the array */

         if ( $paged >= 3 ) {

                     $links[] = $paged - 1;

                     $links[] = $paged - 2;

         }

         if ( ( $paged + 2 ) <= $max ) {

                     $links[] = $paged + 2;

                     $links[] = $paged + 1;

         }

         echo '<div class="navigation"><ul>' . "n";

         /**   Previous Post Link */

         if ( get_previous_posts_link() )

                     printf( '<li>%s</li>' . "n", get_previous_posts_link() );

         /**   Link to first page, plus ellipses if necessary */

         if ( ! in_array( 1, $links ) ) {

                     $class = 1 == $paged ? ' class="active"' : '';

                     printf( '<li%s><a href="https://www.bkns.vn/%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );

                     if ( ! in_array( 2, $links ) )

                                  echo '<li>…</li>';

         }

         /**   Link to current page, plus 2 pages in either direction if necessary */

         sort( $links );

         foreach ( (array) $links as $link ) {

                     $class = $paged == $link ? ' class="active"' : '';

                     printf( '<li%s><a href="https://www.bkns.vn/%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( $link ) ), $link );

         }

         /**   Link to last page, plus ellipses if necessary */

         if ( ! in_array( $max, $links ) ) {

                     if ( ! in_array( $max - 1, $links ) )

                                  echo '<li>…</li>' . "n";

                     $class = $paged == $max ? ' class="active"' : '';

                     printf( '<li%s><a href="https://www.bkns.vn/%s">%s</a></li>' . "n", $class, esc_url( get_pagenum_link( $max ) ), $max );

         }

         /**   Next Post Link */

         if ( get_next_posts_link() )

                     printf( '<li>%s</li>' . "n", get_next_posts_link() );

         echo '</ul></div>' . "n";

}

Bước 3: Thêm giao diện cho Pagination:

.navigation li a,

.navigation li a:hover,

.navigation li.active a,

.navigation li.disabled {

         color: #fff;

         text-decoration:none;

}

.navigation li {

         display: inline;

}

.navigation li a,

.navigation li a:hover,

.navigation li.active a,

.navigation li.disabled {

         background-color: #6FB7E9;

         border-radius: 3px;

         cursor: pointer;

         padding: 12px;

         padding: 0.75rem;

}

.navigation li a:hover,

.navigation li.active a {

         background-color: #3C8DC5;

}

Note: Other values ​​can be changed to best suit your website


Step 4: Add the following code to display Pagination go out:



Step 5: Complete WordPress pagination without using Plugins


Above, BKNS has shown you how to Pagination in WordPress use Plugin and not use Plugin. Hopefully, the information that BKNS provides is useful to you. If you have done it but have not been successful, please leave a comment below the article so that BKNS can promptly respond. Don't forget to visit bkns.vn regularly to update more useful articles!


>> Learn more:



Related Posts
Diệp Quân
Nguyen Manh Cuong is the author and founder of the vmwareplayerfree blog. With over 14 years of experience in Online Marketing, he now runs a number of successful websites, and occasionally shares his experience & knowledge on this blog.
SHARE

Related Posts

Subscribe to get free updates

Post a Comment

Sticky