adding excerpt limit for hover map
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Dec 2017 21:37:58 +0000 (16:37 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 27 Dec 2017 21:37:58 +0000 (16:37 -0500)
using function set limit on the excerpt for the content next to the hover map

functions.php
parts/map-section.php

index f34bd68..acaf946 100644 (file)
@@ -159,7 +159,29 @@ function is_post_type($type){
     if($type == get_post_type($wp_query->post->ID)) return true;
     return false;
 }
+function get_excerpt_by_id($post_id, $length = 35){
+    $the_post = get_post($post_id); //Gets post ID
+    if( $the_post->post_excerpt ){
+       $the_excerpt = $the_post->post_excerpt;
+    } else {
+        $the_excerpt = $the_post->post_content;
+    }
+
+    $excerpt_length = $length; //Sets excerpt length by word count
+    $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images
+    $words = explode(' ', $the_excerpt, $excerpt_length + 1);
+
+    if(count($words) > $excerpt_length) :
+        array_pop($words);
+        array_push($words, '…');
+        $the_excerpt = implode(' ', $words);
+    endif;
 
+//    $the_excerpt = '<p>' . $the_excerpt . '</p>';
+
+    return $the_excerpt;
+}
+?>
 add_action('thematic_searchloop', 'mytheme_search_loop');
 // End of the Contextual/Highlight Search functions
 ?>
index 265a4ff..2b8b49e 100644 (file)
@@ -12,8 +12,8 @@
         $city_page = get_posts($args);
         // echo '<pre>', print_r($city_page), '</pre>';
         if( !empty($city_page) ){
-            // $content = get_excerpt_by_id($city_page[0]->ID, 55);
-            $content        = get_the_excerpt($city_page[0]->ID);
+            $content = get_excerpt_by_id($city_page[0]->ID, 40);
+            // $content        = get_the_excerpt($city_page[0]->ID);
             $city_image_id  = get_post_thumbnail_id($city_page[0]->ID);
             $city_image     = wp_get_attachment_image_src( $city_image_id, 'glm-map-image', true);
             $city_url       = get_permalink($city_page[0]->ID);