Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Includes a few useful predicates in the bootstrapped `infiniteScroll` JS object
- * that is served along with the rest of the document upon initial page request.
- */
- add_filter( 'infinite_scroll_js_settings', 'mcsf_extra_js_settings' );
- function mcsf_extra_js_settings( $js_settings ) {
- $js_settings['query_args']['extra'] = array(
- 'is_home' => is_home(),
- 'is_front_page' => is_front_page(),
- 'is_admin' => is_admin()
- );
- return $js_settings;
- }
- /**
- * Whitelists the `extra` variable that holds the predicates, so that IS doesn't ignore
- * it when reconstructing the original query using the query args from the IS AJAX
- * request.
- *
- * Filter priority is not actually necessary.
- */
- add_filter( 'infinite_scroll_allowed_vars', 'mcsf_allow_extra_vars', 11 );
- function mcsf_allow_extra_vars( $allowed_vars ) {
- $allowed_vars[] = 'extra';
- return $allowed_vars;
- }
- /**
- * Now that we've made these predicates available, let's use them do make our adjustments
- * to $query_args.
- *
- * Filter priority is indeed important, as we need to run this after `inject_query_args`.
- */
- function mcsf_infinite_scroll_query_args_adjust( $query_args ) {
- if ( array_key_exists( 'extra', $query_args ) ) {
- $extra = $query_args['extra'];
- if ( $extra['is_admin'] ) {
- return $query_args;
- }
- if ( $extra['is_home'] || $extra['is_front_page'] ) {
- $query_args['posts_per_page'] = 13;
- } else {
- $query_args['posts_per_page'] = 9;
- }
- }
- return $query_args;
- }
- add_filter( 'infinite_scroll_query_args', 'mcsf_infinite_scroll_query_args_adjust', 11 );
Advertisement
Add Comment
Please, Sign In to add comment