adding checks for thumbnail image and post excerpt before trying
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 16 Dec 2016 17:08:06 +0000 (12:08 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 16 Dec 2016 17:08:06 +0000 (12:08 -0500)
to assign the values to an array for the interactive day trips
dropdown map

parts/interactive-map.php

index a6cc6e0..e6b0660 100644 (file)
@@ -37,9 +37,19 @@ foreach ($nav_posts as $p){
 
     $sites[$p->ID]['url'] = get_permalink( $p->ID );
     $sites[$p->ID]['title'] = get_the_title($p->ID );
-    $image = wp_get_attachment_image_src( get_post_thumbnail_id($p->ID), 'map-image');
-    $sites[$p->ID]['image'] = $image[0];
-    $sites[$p->ID]['excerpt'] = get_the_excerpt( $p->ID );
+    if (has_post_thumbnail($p->ID)){
+        $image = wp_get_attachment_image_src( get_post_thumbnail_id($p->ID), 'map-image');
+        $sites[$p->ID]['image'] = $image[0];
+    } else {
+        $image = get_template_directory_uri() . '/assets/silver-image.jpg';
+        $sites[$p->ID]['image'] = $image;
+    }
+    
+    if (has_excerpt($p->ID)){
+        $sites[$p->ID]['excerpt'] = get_the_excerpt( $p->ID );
+    } else {
+        $sites[$p->ID]['excerpt'] = " ";
+    }
 }
 $js_sites = json_encode($sites);
 ?>