AJDesigns

Matheson theme, custom header for blog page and default post

Apr 28th, 2014
228
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Update I realized that if an individual blog post doesn't have a featured image or custom header, then it will default to the main header, I wanted it to default to the header that is set on the blog page (from above).
  2.  
  3. This sets individual posts to have the same header as the blog page, but only IF there is no custom header or featured image for that page. If there is a featured image it will use that and then look for custom header and then look for custom header on the blog page.
  4.  
  5. Here's the function to replace header_images():
  6.  
  7. function header_images() {
  8. $custom_image = get_post_meta( get_the_ID(), 'matheson_custom_image', true ) ;
  9. $blog_image = get_post_meta( get_option('page_for_posts'), 'matheson_custom_image', true );
  10.  
  11. if ( (is_page() OR is_attachment()) && ( ! empty( $custom_image )) ) {
  12. if ( $custom_image )
  13. echo '<img src="' . esc_url( $custom_image ) . '" alt="" class="header-img" />';
  14. else
  15. the_post_thumbnail( 'full', array( 'class' => 'header-img' ) );
  16. } elseif (is_home()){
  17. echo '<img src="' . esc_url( $blog_image ) . '" alt="" class="header-img" />';
  18. }
  19.  
  20. elseif (is_single() && ($custom_image) )
  21. {
  22. echo '<img src="' . esc_url( $custom_image ) . '" alt="" class="header-img" />';
  23. }
  24.  
  25. elseif (is_single() && (! $custom_image) )
  26.  
  27. {
  28. if ($blog_image) {
  29. echo '<img src="' . esc_url( $blog_image ) . '" alt="" class="header-img" />';}
  30.  
  31. }
  32.  
  33. else {
  34. $header_image = get_header_image();
  35. if ( ! empty( $header_image ) ) {
  36. ?>
  37. <img class="header-img" src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
  38. <?php
  39. }
  40. }
  41. }
  42.  
  43. Edited because of problems when the featured image is set.
  44. (Its still a hack to the parent theme.)
  45. Cheers
RAW Paste Data