header-image.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <div class="custom-header">
  2. <?php
  3. $header_image = get_header_image();
  4. $jetpack_portfolio_featured_image = get_option( 'jetpack_portfolio_featured_image' );
  5. // If this is a single post or page with a featured image (but not a portfolio)
  6. if ( has_post_thumbnail() && ( is_singular() && 'jetpack-portfolio' !== get_post_type() && lodestar_jetpack_featured_image_display() ) ) :
  7. $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  8. $thumbnail_attributes = wp_get_attachment_image_src( $post_thumbnail_id, 'lodestar-featured-image' );
  9. ?>
  10. <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $thumbnail_attributes[0] ); ?>)">
  11. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  12. </div>
  13. <?php
  14. // Else if this is a portfolio archive, and the Portfolio featured image is set
  15. // TODO: Decide if this image should also be shown for Portfolio types and tags archives
  16. elseif (
  17. ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag') || 'jetpack-portfolio' === get_post_type() ) && isset( $jetpack_portfolio_featured_image ) && '' != $jetpack_portfolio_featured_image ) :
  18. $featured_image_attributes = wp_get_attachment_image_src( $jetpack_portfolio_featured_image, 'lodestar-featured-image' );
  19. $ft_image_url = is_array( $featured_image_attributes ) ? $featured_image_attributes[0] : false;
  20. ?>
  21. <div class="custom-header-image" <?php if ( $ft_image_url ) echo 'style="background-image: url(' . esc_url( $ft_image_url ) . ')"'; ?>>
  22. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  23. </div>
  24. <?php
  25. // Else if the Custom Header image has been set
  26. elseif ( ! empty( $header_image ) ) : ?>
  27. <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $header_image ); ?>)">
  28. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  29. </div>
  30. <?php
  31. // Otherwise, show an empty header background.
  32. else : ?>
  33. <div class="custom-header-image">
  34. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  35. </div>
  36. <?php endif; ?>
  37. </div><!-- .custom-header -->