Changeset 4818
- Timestamp:
- 03/21/2013 03:56:08 PM (13 years ago)
- File:
-
- 1 edited
-
trunk/includes/topics/template-tags.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/topics/template-tags.php
r4814 r4818 162 162 // Get super stickies and stickies in this forum 163 163 $stickies = bbp_get_super_stickies(); 164 $stickies = !empty( $r['post_parent'] ) ? array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) ) : $stickies; 164 165 // Get stickies for current forum 166 if ( !empty( $r['post_parent'] ) ) { 167 $stickies = array_merge( $stickies, bbp_get_stickies( $r['post_parent'] ) ); 168 } 169 170 // Remove any duplicate stickies 165 171 $stickies = array_unique( $stickies ); 166 172 … … 168 174 if ( is_array( $stickies ) && !empty( $stickies ) ) { 169 175 170 // Setup the number of stickies and reset offset to 0 171 $num_topics = count( $bbp->topic_query->posts ); 172 $sticky_offset = 0; 176 // Start the offset at -1 so first sticky is at correct 0 offset 177 $sticky_offset = -1; 173 178 174 179 // Loop over topics and relocate stickies to the front. 175 for ( $i = 0; $i < $num_topics; $i++ ) { 176 if ( in_array( $bbp->topic_query->posts[$i]->ID, $stickies ) ) { 177 $sticky = $bbp->topic_query->posts[$i]; 180 foreach ( $stickies as $sticky_index => $sticky_ID ) { 181 182 // Get the post offset from the posts array 183 $post_offsets = wp_filter_object_list( $bbp->topic_query->posts, array( 'ID' => $sticky_ID ), 'OR', 'ID' ); 184 185 // Continue if no post offsets 186 if ( empty( $post_offsets ) ) { 187 continue; 188 } 189 190 // Loop over posts in current query and splice them into position 191 foreach ( array_keys( $post_offsets ) as $post_offset ) { 192 $sticky_offset++; 193 194 $sticky = $bbp->topic_query->posts[$post_offset]; 178 195 179 196 // Remove sticky from current position 180 array_splice( $bbp->topic_query->posts, $ i, 1 );197 array_splice( $bbp->topic_query->posts, $post_offset, 1 ); 181 198 182 199 // Move to front, after other stickies 183 200 array_splice( $bbp->topic_query->posts, $sticky_offset, 0, array( $sticky ) ); 184 201 185 // Increment the sticky offset. The next sticky will be placed at this offset.186 $sticky_offset++;187 188 // Remove post from sticky posts array189 $offset = array_search( $sticky->ID, $stickies );190 191 202 // Cleanup 192 unset( $stickies[$ offset] );193 unset( $sticky );203 unset( $stickies[$sticky_index] ); 204 unset( $sticky ); 194 205 } 206 207 // Cleanup 208 unset( $post_offsets ); 195 209 } 210 211 // Cleanup 212 unset( $sticky_offset ); 196 213 197 214 // If any posts have been excluded specifically, Ignore those that are sticky. … … 213 230 ); 214 231 232 // Cleanup 233 unset( $stickies ); 234 215 235 // What are the default allowed statuses (based on user caps) 216 236 if ( bbp_get_view_all() ) { … … 229 249 $sticky_count = count( $sticky_posts ); 230 250 231 // Loop through stickies and add them to beginning of array 232 foreach ( $sticky_posts as $sticky ) 233 $topics[] = $sticky; 234 235 // Loop through topics and add them to end of array 236 foreach ( $bbp->topic_query->posts as $topic ) 237 $topics[] = $topic; 251 // Merge the stickies topics with the query topics . 252 $bbp->topic_query->posts = array_merge( $sticky_posts, $bbp->topic_query->posts ); 238 253 239 254 // Adjust loop and counts for new sticky positions 240 $bbp->topic_query->posts = $topics;241 255 $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; 242 256 $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; 243 257 244 258 // Cleanup 245 unset( $topics );246 unset( $stickies );247 259 unset( $sticky_posts ); 248 260 } … … 2312 2324 */ 2313 2325 function bbp_get_topic_edit_link( $args = '' ) { 2314 2326 2315 2327 // Parse arguments against default values 2316 2328 $r = bbp_parse_args( $args, array(
Note: See TracChangeset
for help on using the changeset viewer.