Make WordPress Core

Ticket #34487: is_blog_page.diff

File is_blog_page.diff, 1.7 KB (added by roytanck, 9 years ago)

Patch that adds the is_blog_page conditional tag to query.php

  • wp-includes/query.php

     
    456456}
    457457
    458458/**
     459 * Is the query for the 'posts page' of the site?
     460 *
     461 * Conditional tag used to identify the page set as 'posts page' under the Reading settings
     462 *
     463 * If you set a posts page for the front page of your site, this function will return
     464 * true when viewing that page.
     465 *
     466 * @since ?
     467 *
     468 * @global WP_Query $wp_query Global WP_Query instance.
     469 *
     470 * @return bool True, if posts page of site.
     471 */
     472function is_blog_page() {
     473        global $wp_query;
     474
     475        if ( ! isset( $wp_query ) ) {
     476                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     477                return false;
     478        }
     479
     480        return $wp_query->is_blog_page();
     481}
     482
     483/**
    459484 * Is the query for an existing month archive?
    460485 *
    461486 * @since 1.5.0
     
    44744499        }
    44754500
    44764501        /**
     4502         * Is the query for the posts page of the site?
     4503         *
     4504         * Uses is_home, get_queried_object_id and the "reading" options to determine
     4505         * whether the current page is the "posts page"
     4506         *
     4507         * @since ?
     4508         *
     4509         * @return bool True, if posts page of site.
     4510         */
     4511        public function is_blog_page() {
     4512                // check if this is "home", whether the reading setting specify a "posts page", and if this is it
     4513                if( $this->is_home() && 'page' == get_option( 'show_on_front') && get_option('page_for_posts') && ( intval( get_option('page_for_posts') ) == $this->get_queried_object_id() ) ){
     4514                        return true;
     4515                }
     4516                return false;
     4517        }
     4518
     4519        /**
    44774520         * Is the query for an existing month archive?
    44784521         *
    44794522         * @since 3.1.0