added code to functions php to inherit featured image from parent page
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 19 Jan 2016 18:46:45 +0000 (13:46 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 19 Jan 2016 18:46:45 +0000 (13:46 -0500)
functions.php

index 8d32e7b..ec062cf 100644 (file)
@@ -80,10 +80,18 @@ function glm_site_scripts()
 
 /* Header for posts*/
 function glm_get_header() {
+    global $post;
+    
     echo '<div';
+    // inherit featured image from parent pages
+    if ( $post->post_parent ){
+        $post_id = $post->post_parent;
+    }
+    else
+        $post_id = $post->ID;
 
-    if (has_post_thumbnail()) {
-            $image_data = wp_get_attachment_image_src(get_post_thumbnail_id(), "full");
+    if (has_post_thumbnail($post_id)) {
+            $image_data = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), "full");
             echo ' style="background-image: url('.$image_data[0].');height:0;padding:0;padding-bottom:30%;background-position:center center;background-size: 100%;background-repeat:no-repeat;max-height: 420px;min-height: 150px; "';
     } else {
             echo ' style="background-image: url('.get_template_directory_uri().'/assets/things-to-do.jpg);height:0;padding:0;padding-bottom:30%;background-position:center center;background-size: 100%;background-repeat:no-repeat;max-height: 420px; min-height: 150px;"';
@@ -137,4 +145,6 @@ function mytheme_search_loop() {
 add_action('thematic_searchloop', 'mytheme_search_loop');
 // End of the Contextual/Highlight Search functions
 //add_image_size('glm_blocks', '570', '280', true);
+
+
 ?>