WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/25/2010 03:36:23 PM (9 years ago)
Author:
nacin
Message:

Give is_singular the ability to provide awareness/context for custom post types. props ryan, scribu. Usage: is_singular('book') or is_singular( array( 'newspapers', 'books' ) ). fixes #12588.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/query.php

    r14750 r14887  
    146146 * @return bool True if page is author or $author (if set).
    147147 */
    148 function is_author ($author = '') {
     148function is_author($author = '') {
    149149    global $wp_query;
    150150
     
    181181 * @return bool
    182182 */
    183 function is_category ($category = '') {
     183function is_category($category = '') {
    184184    global $wp_query;
    185185
     
    410410 * @return bool
    411411 */
    412 function is_page ($page = '') {
     412function is_page($page = '') {
    413413    global $wp_query;
    414414
     
    530530        return false;
    531531
    532     if ( empty( $post) )
     532    if ( empty($post) )
    533533        return true;
    534534
     
    553553 * @uses $wp_query
    554554 *
     555 * @param string|array $post_types Optional. Post type or types to check in current query.
    555556 * @return bool
    556557 */
    557 function is_singular() {
    558     global $wp_query;
    559 
    560     return $wp_query->is_singular;
     558function is_singular($post_types = '') {
     559    global $wp_query;
     560
     561    if ( empty($post_types) || !$wp_query->is_singular )
     562        return $wp_query->is_singular;
     563
     564    $post_obj = $wp_query->get_queried_object();
     565
     566    return in_array($post_obj->post_type, (array) $post_types);
    561567}
    562568
     
    12381244     * @param string|array $query
    12391245     */
    1240     function parse_query($query ) {
     1246    function parse_query($query) {
    12411247        if ( !empty($query) || !isset($this->query) ) {
    12421248            $this->init();
Note: See TracChangeset for help on using the changeset viewer.