Changeset 1728
- Timestamp:
- 10/02/2004 07:24:40 PM (20 years ago)
- Location:
- trunk/wp-includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/classes.php
r1714 r1728 4 4 var $query; 5 5 var $query_vars; 6 var $queried_object; 7 var $queried_object_id; 6 8 7 9 var $posts; … … 44 46 unset($this->query); 45 47 unset($this->query_vars); 48 unset($this->queried_object); 49 unset($this->queried_object_id); 46 50 $this->post_count = 0; 47 51 $this->current_post = -1; … … 523 527 $this->post_count = count($this->posts); 524 528 if ($this->post_count > 0) { 525 $this->post = $ posts[0];529 $this->post = $this->posts[0]; 526 530 } 527 531 … … 552 556 $this->parse_query($query); 553 557 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; 554 599 } 555 600 -
trunk/wp-includes/functions.php
r1727 r1728 1605 1605 } 1606 1606 1607 function is_single () { 1608 global $wp_query; 1609 1610 return $wp_query->is_single; 1611 } 1612 1613 function is_page () { 1614 global $wp_query; 1615 1616 return $wp_query->is_page; 1607 function is_single ($post = '') { 1608 global $wp_query; 1609 1610 if (! $wp_query->is_single) { 1611 return false; 1612 } 1613 1614 if (empty($post)) { 1615 return true; 1616 } 1617 1618 $post_obj = $wp_query->get_queried_object(); 1619 1620 if ($post == $post_obj->ID) { 1621 return true; 1622 } else if ($post == $post_obj->post_title) { 1623 return true; 1624 } else if ($post == $post_obj->post_name) { 1625 return true; 1626 } 1627 1628 return false; 1629 } 1630 1631 function is_page ($page = '') { 1632 global $wp_query; 1633 1634 if (! $wp_query->is_page) { 1635 return false; 1636 } 1637 1638 if (empty($page)) { 1639 return true; 1640 } 1641 1642 $page_obj = $wp_query->get_queried_object(); 1643 1644 if ($page == $page_obj->ID) { 1645 return true; 1646 } else if ($page == $page_obj->post_title) { 1647 return true; 1648 } else if ($page == $page_obj->post_name) { 1649 return true; 1650 } 1651 1652 return false; 1617 1653 } 1618 1654 … … 1653 1689 } 1654 1690 1655 function is_author () { 1656 global $wp_query; 1657 1658 return $wp_query->is_author; 1659 } 1660 1661 function is_category () { 1662 global $wp_query; 1663 1664 return $wp_query->is_category; 1691 function is_author ($author = '') { 1692 global $wp_query; 1693 1694 if (! $wp_query->is_author) { 1695 return false; 1696 } 1697 1698 if (empty($author)) { 1699 return true; 1700 } 1701 1702 $author_obj = $wp_query->get_queried_object(); 1703 1704 if ($author == $author_obj->ID) { 1705 return true; 1706 } else if ($author == $author_obj->user_nickname) { 1707 return true; 1708 } else if ($author == $author_obj->user_nicename) { 1709 return true; 1710 } 1711 1712 return false; 1713 } 1714 1715 function is_category ($category = '') { 1716 global $wp_query; 1717 1718 if (! $wp_query->is_category) { 1719 return false; 1720 } 1721 1722 if (empty($category)) { 1723 return true; 1724 } 1725 1726 $cat_obj = $wp_query->get_queried_object(); 1727 1728 if ($category == $cat_obj->cat_ID) { 1729 return true; 1730 } else if ($category == $cat_obj->cat_name) { 1731 return true; 1732 } else if ($category == $cat_obj->category_nicename) { 1733 return true; 1734 } 1735 1736 return false; 1665 1737 } 1666 1738
Note: See TracChangeset
for help on using the changeset viewer.