is_main_query() ) { $wp_query->set( 'cache_results', false ); return []; } return $posts; } /** * Filter: posts_fields */ public static function empty_posts_fields( string $fields, \WP_Query $wp_query ) { if ( $wp_query->is_main_query() ) { return '1'; } return $fields; } /** * Filter: home_template, frontpage_template and index_template */ public static function load_custom_template() { return get_template_directory() . '/inc/pages-index/templates/tpl-pages-index.php'; } /** * When the front page is set to a static page, Pages Index * is wrongly tagged as '404'. This is to handle P2s * that need their front page to be static, e.g. document-heavy P2s. */ public static function prevent_404s() { // Extra check: this should only apply to the Pages Index. if ( ! self::is_pages_index_active() ) { return; } global $wp_query; status_header( 200 ); $wp_query->is_404 = false; } public static function custom_body_class( $classes ) { // Add special pages index class. $classes[] = 'is-pages-index'; // Remove 'home' class. return array_diff( $classes, [ 'home' ] ); } public static function remove_infinite_scroll() { remove_theme_support( 'infinite-scroll' ); } public static function customize_o2_options( array $o2_options ) { $o2_options['options']['infiniteScroll'] = false; $o2_options['options']['hideAppControls'] = true; $o2_options['options']['showFrontSidePostBox'] = false; $o2_options['options']['viewType'] = 'archive'; return $o2_options; } public static function print_pages_tree() { $options = array( 'title_li' => '', 'sort_column' => 'menu_order, post_title', 'echo' => 0, 'walker' => new Custom_Walker_Page(), ); // Exclude page set as Posts page, to keep this list only for // actual pages, in the context of P2. $page_for_posts = get_option( 'page_for_posts' ); if ( ! empty( $page_for_posts ) ) { $options['exclude'] = $page_for_posts; } // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo \wp_list_pages( $options ); } public static function is_pages_index_active(): bool { return isset( $_GET['pages'] ); } public static function get_pages_index_url(): string { return add_query_arg( [ 'pages' => true ], get_home_url() ); } }