From: Anthony Talarico Date: Wed, 27 Dec 2017 21:37:58 +0000 (-0500) Subject: adding excerpt limit for hover map X-Git-Tag: v1.0.0^2~24 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=d987e3e7c77249ed553ffdc37300734f75e1641f;p=WP-Themes%2Fvisitescanaba.git adding excerpt limit for hover map using function set limit on the excerpt for the content next to the hover map --- 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);