[wp-cvs]
wordpress/wp-includes classes.php, 1.20, 1.21 functions.php,
1.174, 1.175
Ryan Boren
rboren at users.sourceforge.net
Sat Oct 2 19:24:43 UTC 2004
Update of /cvsroot/cafelog/wordpress/wp-includes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5491/wp-includes
Modified Files:
classes.php functions.php
Log Message:
Extend is_single(), is_page(), is_category(), and is_author() to accept an optional argument which designates a particular id, name, or nicename.
Index: functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/functions.php,v
retrieving revision 1.174
retrieving revision 1.175
diff -C2 -d -r1.174 -r1.175
*** functions.php 2 Oct 2004 00:46:29 -0000 1.174
--- functions.php 2 Oct 2004 19:24:40 -0000 1.175
***************
*** 1605,1618 ****
}
! function is_single () {
! global $wp_query;
! return $wp_query->is_single;
}
! function is_page () {
! global $wp_query;
! return $wp_query->is_page;
}
--- 1605,1654 ----
}
! function is_single ($post = '') {
! global $wp_query;
! if (! $wp_query->is_single) {
! return false;
! }
!
! if (empty($post)) {
! return true;
! }
!
! $post_obj = $wp_query->get_queried_object();
!
! if ($post == $post_obj->ID) {
! return true;
! } else if ($post == $post_obj->post_title) {
! return true;
! } else if ($post == $post_obj->post_name) {
! return true;
! }
!
! return false;
}
! function is_page ($page = '') {
! global $wp_query;
! if (! $wp_query->is_page) {
! return false;
! }
!
! if (empty($page)) {
! return true;
! }
!
! $page_obj = $wp_query->get_queried_object();
!
! if ($page == $page_obj->ID) {
! return true;
! } else if ($page == $page_obj->post_title) {
! return true;
! } else if ($page == $page_obj->post_name) {
! return true;
! }
!
! return false;
}
***************
*** 1653,1666 ****
}
! function is_author () {
! global $wp_query;
! return $wp_query->is_author;
}
! function is_category () {
! global $wp_query;
! return $wp_query->is_category;
}
--- 1689,1738 ----
}
! function is_author ($author = '') {
! global $wp_query;
! if (! $wp_query->is_author) {
! return false;
! }
!
! if (empty($author)) {
! return true;
! }
!
! $author_obj = $wp_query->get_queried_object();
!
! if ($author == $author_obj->ID) {
! return true;
! } else if ($author == $author_obj->user_nickname) {
! return true;
! } else if ($author == $author_obj->user_nicename) {
! return true;
! }
!
! return false;
}
! function is_category ($category = '') {
! global $wp_query;
! if (! $wp_query->is_category) {
! return false;
! }
!
! if (empty($category)) {
! return true;
! }
!
! $cat_obj = $wp_query->get_queried_object();
!
! if ($category == $cat_obj->cat_ID) {
! return true;
! } else if ($category == $cat_obj->cat_name) {
! return true;
! } else if ($category == $cat_obj->category_nicename) {
! return true;
! }
!
! return false;
}
Index: classes.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-includes/classes.php,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** classes.php 27 Sep 2004 00:46:42 -0000 1.20
--- classes.php 2 Oct 2004 19:24:40 -0000 1.21
***************
*** 4,7 ****
--- 4,9 ----
var $query;
var $query_vars;
+ var $queried_object;
+ var $queried_object_id;
var $posts;
***************
*** 44,47 ****
--- 46,51 ----
unset($this->query);
unset($this->query_vars);
+ unset($this->queried_object);
+ unset($this->queried_object_id);
$this->post_count = 0;
$this->current_post = -1;
***************
*** 523,527 ****
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
! $this->post = $posts[0];
}
--- 527,531 ----
$this->post_count = count($this->posts);
if ($this->post_count > 0) {
! $this->post = $this->posts[0];
}
***************
*** 554,557 ****
--- 558,602 ----
}
+ function get_queried_object() {
+ if (isset($this->queried_object)) {
+ return $this->queried_object;
+ }
+
+ $this->queried_object = NULL;
+ $this->queried_object_id = 0;
+
+ if ($this->is_category) {
+ global $cache_categories;
+ if (isset($cache_categories[$this->get('cat')])) {
+ $this->queried_object = $cache_categories[$this->get('cat')];
+ $this->queried_object_id = $this->get('cat');
+ }
+ } else if ($this->is_single) {
+ $this->queried_object = $this->post;
+ $this->queried_object_id = $this->post->ID;
+ } else if ($this->is_page) {
+ $this->queried_object = $this->post;
+ $this->queried_object_id = $this->post->ID;
+ } else if ($this->is_author) {
+ global $cache_userdata;
+ if (isset($cache_userdata[$this->get('author')])) {
+ $this->queried_object = $cache_userdata[$this->get('author')];
+ $this->queried_object_id = $this->get('author');
+ }
+ }
+
+ return $this->queried_object;
+ }
+
+ function get_queried_object_id() {
+ $this->get_queried_object();
+
+ if (isset($this->queried_object_id)) {
+ return $this->queried_object_id;
+ }
+
+ return 0;
+ }
+
function WP_Query ($query = '') {
if (! empty($query)) {
More information about the cvs
mailing list