Created
May 30, 2016 16:33
-
-
Save brubrant/aba430d54ec2551c99a10a0722eed3a7 to your computer and use it in GitHub Desktop.
A lot of configuration of jetpack inifnite scroll settings
This file contains hidden or 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 | |
/*------------------------------------*\ | |
Jetpack infinite Scroll Stufff | |
\*------------------------------------*/ | |
function enable_infinite_scroll_for_blog() { | |
// General Conditions | |
add_theme_support( 'infinite-scroll', array( | |
'type' => 'click', | |
'wrapper' => false, | |
'container' => 'maisPosts', | |
'render' => 'render_posts' | |
) ); | |
function render_posts () { | |
get_template_part( 'loop-load-more' ); | |
} | |
} | |
add_action( 'after_setup_theme', 'enable_infinite_scroll_for_blog' ); | |
// Posts ordered by queryvar "tri" | |
function change_empreendedor_query($query) { | |
if( !is_admin() && $query->is_main_query() && is_post_type_archive( 'empreendedor' ) ) { | |
// $query->set( 'posts_per_page', 4); | |
$query->set( 'meta_key','simplefavorites_count'); | |
$query->set( 'orderby' , 'meta_value_num' ); | |
$query->set('order', 'DESC' ); | |
} | |
} | |
add_action('pre_get_posts','change_empreendedor_query'); | |
// 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 * request. | |
function infinite_scroll_allowed_vars_extra( $allowed_vars ) { | |
$allowed_vars[] = 'extra'; | |
return $allowed_vars; | |
} | |
add_filter( 'infinite_scroll_allowed_vars', 'infinite_scroll_allowed_vars_extra',150 ); | |
// 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. | |
// function infinite_scroll_js_settings_extra( $js_settings ) { | |
// $js_settings['text'] = __( "Mais empreendedor", "pla" ); | |
// return $js_settings; | |
// } | |
// add_filter( 'infinite_scroll_js_settings', 'infinite_scroll_js_settings_extra' ); | |
function change_infinite_setting( $args ) { | |
if( is_post_type_archive( array( 'mentor' ) ) ) { | |
$args['posts_per_page'] = 28; | |
$args['container'] = 'mentores'; | |
} | |
if( is_post_type_archive( array( 'empreendedor' ) ) ) { | |
$args['container'] = 'maisPosts'; | |
$args['posts_per_page'] = 12; | |
} | |
return $args; | |
} | |
add_filter( 'infinite_scroll_settings', 'change_infinite_setting' ); | |
function filter_inifite_query( $args ) { | |
if( 'empreendedor' === $args['post_type'] ) { | |
$args['posts_per_page'] = 12; | |
$args['order'] = 'DESC'; | |
$args['orderby'] = 'meta_value_num'; | |
$args['container'] = 'maisPosts'; | |
$args['meta_key'] = 'simplefavorites_count'; | |
$args['offset'] = $args['posts_per_page'] * $args['paged']; | |
// $args['paged']++; | |
} | |
return $args; | |
} | |
add_filter( 'infinite_scroll_query_args', 'filter_inifite_query', 11); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment