Created
March 13, 2020 20:40
-
-
Save wpsmith/345bf2ed95fc89bffea2e7dab75d4ccf to your computer and use it in GitHub Desktop.
WP: Add pagination to pages (though definitely not recommended).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add URL rewrite to recognize the pagination. | |
add_action( 'init', function () { | |
add_rewrite_rule( '(.?.+?)/page/?([0-9]{1,})/?$', 'index.php?pagename=$matches[1]&paged=$matches[2]', 'top' ); | |
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Agenda | |
* | |
* This file adds the agenda template to the the theme. | |
* | |
* Template Name: Agenda | |
*/ | |
namespace WPS\WP\Templates; | |
add_action( 'genesis_meta', __NAMESPACE__ . '\page_setup' ); | |
/** | |
* Remove the default loop. | |
*/ | |
function page_setup() { | |
remove_action( 'genesis_loop', 'genesis_do_loop' ); | |
add_action( 'genesis_loop', __NAMESPACE__ . '\do_loop' ); | |
} | |
/** | |
* The custom loop | |
*/ | |
function do_loop() { | |
// Get the pagination. | |
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; | |
$args = array( | |
'post_type' => 'agenda', | |
'post_status' => 'publish', | |
'paged' => intval( $paged ), | |
); | |
// Do our custom loop genesis style. | |
genesis_custom_loop( wp_parse_args( | |
genesis_get_custom_field( 'query_args' ), | |
$args | |
); | |
} | |
// Let's go! | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment