Changeset 8546 for trunk/wp-includes/query.php
- Timestamp:
- 08/05/2008 05:48:21 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/query.php
r8504 r8546 832 832 $post_status_join = false; 833 833 834 if ( !isset($q['caller_get_posts']) ) 835 $q['caller_get_posts'] = false; 836 834 837 if ( !isset($q['post_type']) ) { 835 838 if ( $this->is_search ) … … 1495 1498 } 1496 1499 } 1500 } 1501 } 1502 1503 // Put sticky posts at the top of the posts array 1504 $sticky_posts = get_option('sticky_posts'); 1505 if ( $this->is_home && $page <= 1 && !empty($sticky_posts) && !$q['caller_get_posts'] ) { 1506 $num_posts = count($this->posts); 1507 $sticky_offset = 0; 1508 // Loop over posts and relocate stickies to the front. 1509 for ( $i = 0; $i < $num_posts; $i++ ) { 1510 if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { 1511 $sticky_post = $this->posts[$i]; 1512 // Remove sticky from current position 1513 array_splice($this->posts, $i, 1); 1514 // Move to front, after other stickies 1515 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 1516 // Increment the sticky offset. The next sticky will be placed at this offset. 1517 $sticky_offset++; 1518 // Remove post from sticky posts array 1519 $offset = array_search($sticky_post->ID, $sticky_posts); 1520 array_splice($sticky_posts, $offset, 1); 1521 } 1522 } 1523 1524 // Fetch sticky posts that weren't in the query results 1525 $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); 1526 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in)" ); 1527 // TODO Make sure post is published or viewable by the current user 1528 foreach ( $stickies as $sticky_post ) { 1529 if ( 'publish' != $sticky_post->post_status ) 1530 continue; 1531 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 1532 $sticky_offset++; 1497 1533 } 1498 1534 }
Note: See TracChangeset
for help on using the changeset viewer.