twentyfifteen_post_nav_background

Add featured image as background image to post navigation elements.

Description

twentyfifteen_post_nav_background(); 

Usage

  1. if ( !function_exists( 'twentyfifteen_post_nav_background' ) ) { 
  2. require_once '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = twentyfifteen_post_nav_background(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/functions.php  
  1. function twentyfifteen_post_nav_background() { 
  2. if ( ! is_single() ) { 
  3. return; 
  4.  
  5. $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true ); 
  6. $next = get_adjacent_post( false, '', false ); 
  7. $css = ''; 
  8.  
  9. if ( is_attachment() && 'attachment' == $previous->post_type ) { 
  10. return; 
  11.  
  12. if ( $previous && has_post_thumbnail( $previous->ID ) ) { 
  13. $prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' ); 
  14. $css .= ' 
  15. .post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); } 
  16. .post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; } 
  17. .post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); } 
  18. '; 
  19.  
  20. if ( $next && has_post_thumbnail( $next->ID ) ) { 
  21. $nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' ); 
  22. $css .= ' 
  23. .post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; } 
  24. .post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; } 
  25. .post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); } 
  26. '; 
  27.  
  28. wp_add_inline_style( 'twentyfifteen-style', $css );