Add Pagination To Custom Post Type Archive Pages

Simply paste this PHP code at the end of your child themes functions.php file.

The code controls how many CPT items display per archive page. It adds previous and next page links after each archive page for custom post types

If you have published 18 single CPT pages, this code will create 3 paginated pages.

Change Your CPT Name in the code to the name you used to create a custom post type in your functions file.

To control how many single CPT entries display on each page, change the number 6 to suit your own requirements.

You could also modify this code for use on custom taxonomy type archive pages simply by changing the conditional tag from:

is_post_type_archive( 'Your CPT Name' )

to

is_tax( 'Your Taxonomy Name' )

This solution adds page navigation to a custom post type archive page assuming you have created your custom post type using this code in Genesis.

If you used any other code to register your CPT, you may need another solution.

Related Code Snippets


Comments

4 responses to “Add Pagination To Custom Post Type Archive Pages”

  1. I got it working after I changed the number of blogs under reading settings to match to my template settings. My goodness.

    1. Brad Dalton Avatar
      Brad Dalton

      hahaha Good stuff Lex!

  2. I added pagination with the following code

    [code]
    echo get_previous_posts_link( ‘Newer Entries’ ); // display newer posts link
    echo get_next_posts_link( ‘Older Entries’, $the_query->max_num_pages );
    [/code]

    When I click them, url changes to …/vlogs/page/4/ no problem, but the pages stays the same. it always lists just the latest posts. Hmm…

  3. This works for the standard loop. How do I add pagination to a custom loop.


    remove_action ('genesis_loop', 'genesis_do_loop'); // Remove the standard loop
    add_action( 'genesis_loop', 'custom_do_grid_loop' ); // Add custom loop

    And I have my loop working, but I don’t have pagination

    Thank you.

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.