October 5, 2021

Custom Pagination in WordPress

For custom pagination Add Following code in your current themes functions.php file.

if(!$numpages) {
$numpages = 1;

$pagination_args = array(
‘base’ => get_pagenum_link(1) . ‘%_%’,
‘format’ => ‘page/%#%’,
‘total’ => $numpages,
‘current’ => $paged,
‘show_all’ => False,
‘end_size’ => 1,
‘mid_size’ => $pagerange,
‘prev_next’ => True,
‘prev_text’ => __(‘«’),
‘next_text’ => __(‘»’),
‘type’ => ‘array’,
‘add_args’ => false,
‘add_fragment’ => ”

$paginate_links = paginate_links($pagination_args);

if (is_array($paginate_links)) {
echo “

echo ‘

    foreach ( $paginate_links as $page ) {
    echo “

  • $page
  • “;
    echo ‘

echo “


//call your pagination function in your post loop

$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args = array(
‘paged’ => $paged, // pass paged parameter
‘post_type’=> ‘post’,
‘orderby’ => ‘ID’,
‘post_status’ => ‘publish’,
‘order’ => ‘DESC’,
‘posts_per_page’ => 4
$result = new WP_Query( $args );
if ( $result-> have_posts() ) :
while ( $result->have_posts() ) : $result->the_post();
wc_custom_pagination($result->max_num_pages,””, $paged); // call pagination function after post loop


Related Post

How to Add Excerpts to Your Pages in WordPress

you will need to add the following code to your current themes functions.php file

Create Custom Template for Child Categories in WordPress

Create different template only for child category put following code in your current themes functions.php file

Featured image metabox not appearing on custom post edit page

Sometimes theme not support featured image metabox, when put following code in your current themes functions.php file. function my_custom_theme_setup() { add_theme_support( ‘menus’ ); add_theme_support( ‘post-thumbnails’ ); // other options } add_action( ‘after_setup_theme’, ‘my_custom_theme_setup’ ); Now featured image metabox support in custom post edit page.

Redirect to Checkout after add to cart WooCommerce

Redirecting the user to the checkout page when they’ve added a product to their cart. This may come in handy if you only sell one product / one product per time. The filter woocommerce_add_to_cart_redirect makes it easy to redirect user to custom page. Code goes in function.php file of your active child theme (or active […]

WordPress Change Password Form Without Plugin

Are you need simple Change Password form without plugin for your WordPress website? Yes, Then i have created [wc_change_pwd_form] shortcode with quick simple code. So you can put Change Password form anywhere like in Pages, Posts and Widget etc… Therefore you just need to put [wc_change_pwd_form] shortcode where you need Change Password form. So you […]

how to Upload WordPress Custom Meta Box Image

Hi, here i implement multiple image upload custom fields (WordPress custom meta box image upload ) to page post type if you want it for another post type just change post type name. Add the following code to your current themes function.php file. Go to your pages from WordPress admin and check that multiple image […]

Leave a Reply

Your email address will not be published. Required fields are marked *