secret

Adjusts homepage query if the "Magazine" template is used as the homepage.

  • Download Gist
magazine-template-query-adjustment.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
if ( ! function_exists( 'woo_modify_magazine_homepage_query' ) ) {
function woo_modify_magazine_homepage_query ( $q ) {
if ( ! is_admin() && $q->is_main_query() && ( 0 < $q->query_vars['page_id'] ) && ( $q->query_vars['page_id'] == get_option( 'page_on_front' ) ) && ( 'template-magazine.php' == get_post_meta( intval( $q->query_vars['page_id'] ), '_wp_page_template', true ) ) ) {
 
$settings = woo_get_dynamic_values( array( 'magazine_limit' => get_option( 'posts_per_page' ) ) );
 
$q->set( 'posts_per_page', intval( $settings['magazine_limit'] ) );
$q->set( 'paged', intval( $q->query_vars['page'] ) );
 
$q->parse_query();
}
return $q;
} // End woo_modify_magazine_homepage_query()
}
 
add_filter( 'pre_get_posts', 'woo_modify_magazine_homepage_query' );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.