Good plugin. An example of using a theme (with Twenty 15):
1. User template page
Create the page-pjax.php inside the theme.
In the administrator, create a page and use this template. It simply displays archive links with a range around them.
<?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php $args = array( 'type' => 'daily', 'limit' => '', 'format' => 'html', 'before' => '<span class="a-pjax">', 'after' => '</span>', 'show_post_count' => true, 'echo' => 1, 'order' => 'DESC' ); wp_get_archives( $args ); ?> <div id="pjax-container"></div> </main> </div> <?php get_footer(); ?>
2. Add the pjax plugin and user script
In the /js folder on the subject, add jquery.pjax.js and the following script my-pjax.js .
jQuery(document).ready(function($) { $(document).pjax('span.a-pjax a, #recent-posts-2 a', '#pjax-container', {fragment:'#main'}) });
3. Download jQuery, pjax and our custom script
In functions.php . Loaded only on the template page.
add_action( 'wp_enqueue_scripts', 'load_scripts_so_43903250' ); function load_scripts_so_43903250() { if ( is_page_template( 'page-pjax.php' ) ) { wp_register_script( 'pjax', get_stylesheet_directory_uri() . '/js/jquery.pjax.js' ); wp_enqueue_script( 'my-pjax', get_stylesheet_directory_uri() . '/js/my-pjax.js', array('jquery','pjax') ); } }
4. NOTES
$(document).pjax( 'span.a-pjax a, #recent-posts-2 a', // ANCHORS '#pjax-container', // TARGET {fragment:'#main'} // OPTIONS );
ANCHORS are links to the archive and the Recent posts widget with the identifier #recent-posts-2 . Delete it for this test or add another container of links if you want.
TARGET is hardcoded in the template.
OPTIONS, a snippet is necessary because pjax does not load full HTML pages, we must say which part of the landing page we want.
Twenty-fifteen content is inside this div: <main id="main" class="site-main" role="main"> . Adjust according to the theme used.
See pjax notes: https://github.com/defunkt/jquery-pjax#response-types-that-force-a-reload