Ticket #25330: 25330.patch
| File 25330.patch, 3.5 KB (added by , 13 years ago) |
|---|
-
wp-content/themes/twentyfourteen/functions.php
369 369 } 370 370 371 371 /** 372 * Filter the home page posts, and remove formatted posts visible in the sidebar from it372 * Remove the posts visible in the sidebar from the blog home. 373 373 * 374 374 */ 375 375 function twentyfourteen_pre_get_posts( $query ) { 376 // Bail if not home, not a query, not main query.377 if ( ! $query->is_ main_query() || is_admin() )376 // Bail if we're not on the blog home, if it is not the main query or if we are in the admin. 377 if ( ! $query->is_home() || ! $query->is_main_query() || is_admin() ) 378 378 return; 379 379 380 // Only on the home page 381 if ( $query->is_home() ) { 382 $exclude_ids = array(); 380 // Use the cached post IDs to exclude if they exist. 381 $cached_exclude_ids = get_transient( 'twentyfourteen_ephemera_to_exclude' ); 383 382 384 $videos = twentyfourteen_get_recent( 'post-format-video' ); 385 $images = twentyfourteen_get_recent( 'post-format-image' ); 386 $galleries = twentyfourteen_get_recent( 'post-format-gallery' ); 387 $asides = twentyfourteen_get_recent( 'post-format-aside' ); 388 $links = twentyfourteen_get_recent( 'post-format-link' ); 389 $quotes = twentyfourteen_get_recent( 'post-format-quote' ); 383 if ( false !== $cached_exclude_ids ) { 384 $query->set( 'post__not_in', $cached_exclude_ids ); 385 return; 386 } 390 387 391 foreach ( $videos->posts as $post )392 $exclude_ids[] = $post->ID;388 // Fetch the post IDs to exclude and cache them before use. 389 $widget_settings = get_option( 'widget_widget_twentyfourteen_ephemera' ); 393 390 394 foreach ( $images->posts as $post)395 $exclude_ids[] = $post->ID;391 if ( false === $widget_settings ) 392 return; 396 393 397 foreach ( $galleries->posts as $post ) 398 $exclude_ids[] = $post->ID; 394 $exclude_ids = array(); 399 395 400 foreach ( $asides->posts as $post ) 401 $exclude_ids[] = $post->ID; 396 foreach ( $widget_settings as $setting ) { 397 if ( isset( $setting['format'] ) && isset( $setting['number'] ) ) { 398 $posts_to_exclude = new WP_Query( array( 399 'order' => 'DESC', 400 'posts_per_page' => $setting['number'], 401 'no_found_rows' => true, 402 'post_status' => 'publish', 403 'post__not_in' => get_option( 'sticky_posts' ), 404 'tax_query' => array( 405 array( 406 'taxonomy' => 'post_format', 407 'terms' => array( 'post-format-' . $setting['format'] ), 408 'field' => 'slug', 409 'operator' => 'IN', 410 ), 411 ), 412 'fields' => 'ids' 413 ) ); 402 414 403 foreach ( $links->posts as $post ) 404 $exclude_ids[] = $post->ID; 415 if( isset( $posts_to_exclude->posts ) && ! empty ( $posts_to_exclude->posts ) ) { 416 $exclude_ids = array_merge( $exclude_ids, $posts_to_exclude->posts ); 417 } 418 } 419 } 405 420 406 foreach ( $quotes->posts as $post ) 407 $exclude_ids[] = $post->ID; 408 409 $query->set( 'post__not_in', $exclude_ids ); 410 } 421 set_transient( 'twentyfourteen_ephemera_to_exclude', $exclude_ids ); 422 $query->set( 'post__not_in', $exclude_ids ); 411 423 } 412 424 add_action( 'pre_get_posts', 'twentyfourteen_pre_get_posts' ); 413 425 -
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 /**