Skip to content

Instantly share code, notes, and snippets.

@wpsmith
Created March 13, 2020 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpsmith/345bf2ed95fc89bffea2e7dab75d4ccf to your computer and use it in GitHub Desktop.
Save wpsmith/345bf2ed95fc89bffea2e7dab75d4ccf to your computer and use it in GitHub Desktop.
WP: Add pagination to pages (though definitely not recommended).
<?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' );
} );
<?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