Make WordPress Core


Ignore:
Timestamp:
10/02/2004 07:24:40 PM (20 years ago)
Author:
rboren
Message:

Extend is_single(), is_page(), is_category(), and is_author() to accept an optional argument which designates a particular id, name, or nicename.

File:
1 edited

Legend:

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

    r1714 r1728  
    44    var $query;
    55    var $query_vars;
     6    var $queried_object;
     7    var $queried_object_id;
    68
    79    var $posts;
     
    4446        unset($this->query);
    4547        unset($this->query_vars);
     48        unset($this->queried_object);
     49        unset($this->queried_object_id);
    4650        $this->post_count = 0;
    4751        $this->current_post = -1;
     
    523527        $this->post_count = count($this->posts);
    524528        if ($this->post_count > 0) {
    525             $this->post = $posts[0];
     529            $this->post = $this->posts[0];
    526530        }
    527531
     
    552556        $this->parse_query($query);
    553557        return $this->get_posts();
     558    }
     559
     560    function get_queried_object() {
     561        if (isset($this->queried_object)) {
     562            return $this->queried_object;
     563        }
     564
     565        $this->queried_object = NULL;
     566        $this->queried_object_id = 0;
     567
     568        if ($this->is_category) {
     569            global $cache_categories;
     570            if (isset($cache_categories[$this->get('cat')])) {
     571                $this->queried_object = $cache_categories[$this->get('cat')];
     572                $this->queried_object_id = $this->get('cat');
     573            }
     574        } else if ($this->is_single) {
     575            $this->queried_object = $this->post;
     576            $this->queried_object_id = $this->post->ID;
     577        } else if ($this->is_page) {
     578            $this->queried_object = $this->post;
     579            $this->queried_object_id = $this->post->ID;
     580        } else if ($this->is_author) {
     581            global $cache_userdata;
     582            if (isset($cache_userdata[$this->get('author')])) {
     583                $this->queried_object = $cache_userdata[$this->get('author')];
     584                $this->queried_object_id = $this->get('author');
     585            }
     586        }
     587
     588        return $this->queried_object;
     589    }
     590
     591    function get_queried_object_id() {
     592        $this->get_queried_object();
     593
     594        if (isset($this->queried_object_id)) {
     595            return $this->queried_object_id;
     596        }
     597
     598        return 0;
    554599    }
    555600
Note: See TracChangeset for help on using the changeset viewer.