How to add page pagination on custom wordpress page?

by lindsey.homenick , in category: PHP CMS , 7 months ago

How to add page pagination on custom wordpress page?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 7 months ago

@lindsey.homenick 

To add page pagination on a custom Wordpress page, follow these steps:

  1. Determine the location where you want to display the pagination. This is usually at the bottom of the page.
  2. Open your theme's "functions.php" file. You can find this file by going to Appearance > Theme Editor in your Wordpress admin panel.
  3. Add the following code to the "functions.php" file:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function custom_pagination() {
    global $wp_query;
   
    $pager = 999999999;
   
    echo paginate_links(array(
        'base' => str_replace($pager, '%#%', esc_url(get_pagenum_link($pager))),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged')),
        'total' => $wp_query->max_num_pages,
    ));
}


  1. Save the changes in the "functions.php" file.
  2. Open your custom page template file. This is the file that you have created for your custom Wordpress page.
  3. Add the following code where you want to display the pagination:
1
<?php custom_pagination(); ?>


  1. Save the changes in your custom page template file.


Now, when you view your custom Wordpress page, you should see the pagination at the specified location. The pagination will automatically adjust based on the number of pages in your query.