From d987e3e7c77249ed553ffdc37300734f75e1641f Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 27 Dec 2017 16:37:58 -0500 Subject: [PATCH] adding excerpt limit for hover map using function set limit on the excerpt for the content next to the hover map --- functions.php | 22 ++++++++++++++++++++++ parts/map-section.php | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/functions.php b/functions.php index f34bd68..acaf946 100644 --- a/functions.php +++ b/functions.php @@ -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 = '

' . $the_excerpt . '

'; + + return $the_excerpt; +} +?> add_action('thematic_searchloop', 'mytheme_search_loop'); // End of the Contextual/Highlight Search functions ?> diff --git a/parts/map-section.php b/parts/map-section.php index 265a4ff..2b8b49e 100644 --- a/parts/map-section.php +++ b/parts/map-section.php @@ -12,8 +12,8 @@ $city_page = get_posts($args); // echo '
', print_r($city_page), '
'; 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); -- 2.17.1