Ticket #25330: 25330.2.patch
| File 25330.2.patch, 3.5 KB (added by , 12 years ago) |
|---|
-
wp-content/themes/twentyfourteen/functions.php
408 408 } 409 409 410 410 /** 411 * Filter the home page posts, and remove formatted posts visible in the sidebar from it411 * Remove the posts visible in the sidebar from the blog home. 412 412 * 413 * @param WP_Query $query 414 * @return void 413 415 */ 414 416 function twentyfourteen_pre_get_posts( $query ) { 415 // Bail if not home, not a query, not main query.416 if ( ! $query->is_ main_query() || is_admin() )417 // Bail if we're not on the blog home, if it is not the main query or if we are in the admin. 418 if ( ! $query->is_home() || ! $query->is_main_query() || is_admin() ) 417 419 return; 418 420 419 // Only on the home page 420 if ( $query->is_home() ) { 421 $exclude_ids = array(); 421 // Use the cached post IDs to exclude if they exist. 422 $cached_exclude_ids = get_transient( 'twentyfourteen_ephemera_to_exclude' ); 422 423 423 $videos = twentyfourteen_get_recent( 'post-format-video' ); 424 $images = twentyfourteen_get_recent( 'post-format-image' ); 425 $galleries = twentyfourteen_get_recent( 'post-format-gallery' ); 426 $asides = twentyfourteen_get_recent( 'post-format-aside' ); 427 $links = twentyfourteen_get_recent( 'post-format-link' ); 428 $quotes = twentyfourteen_get_recent( 'post-format-quote' ); 424 if ( false !== $cached_exclude_ids ) { 425 $query->set( 'post__not_in', $cached_exclude_ids ); 426 return; 427 } 429 428 430 foreach ( $videos->posts as $post )431 $exclude_ids[] = $post->ID;429 // Fetch the post IDs to exclude and cache them before use. 430 $widget_settings = get_option( 'widget_widget_twentyfourteen_ephemera' ); 432 431 433 foreach ( $images->posts as $post)434 $exclude_ids[] = $post->ID;432 if ( false === $widget_settings ) 433 return; 435 434 436 foreach ( $galleries->posts as $post ) 437 $exclude_ids[] = $post->ID; 435 $exclude_ids = array(); 438 436 439 foreach ( $asides->posts as $post ) 440 $exclude_ids[] = $post->ID; 437 foreach ( $widget_settings as $setting ) { 438 if ( isset( $setting['format'] ) && isset( $setting['number'] ) ) { 439 $posts_to_exclude = get_posts( array( 440 'order' => 'DESC', 441 'numberposts' => $setting['number'], 442 'post_status' => 'publish', 443 'tax_query' => array( 444 array( 445 'taxonomy' => 'post_format', 446 'terms' => array( 'post-format-' . $setting['format'] ), 447 'field' => 'slug', 448 'operator' => 'IN', 449 ), 450 ), 451 ) ); 441 452 442 foreach ( $links->posts as $post ) 443 $exclude_ids[] = $post->ID; 453 if ( ! empty ( $posts_to_exclude ) ) { 454 $posts_to_exclude = wp_list_pluck( $posts_to_exclude, 'ID' ); 455 $exclude_ids = array_merge( $exclude_ids, $posts_to_exclude ); 456 } 457 } 458 } 444 459 445 foreach ( $quotes->posts as $post ) 446 $exclude_ids[] = $post->ID; 447 448 $query->set( 'post__not_in', $exclude_ids ); 449 } 460 $exclude_ids = array_unique( $exclude_ids ); 461 set_transient( 'twentyfourteen_ephemera_to_exclude', $exclude_ids ); 462 $query->set( 'post__not_in', $exclude_ids ); 450 463 } 451 464 add_action( 'pre_get_posts', 'twentyfourteen_pre_get_posts' ); 452 465 -
wp-content/themes/twentyfourteen/inc/widgets.php
218 218 */ 219 219 function flush_widget_cache() { 220 220 delete_transient( $this->id ); 221 delete_transient( 'twentyfourteen_ephemera_to_exclude' ); 221 222 } 222 223 223 224 /**