From: Anthony Talarico Date: Mon, 11 Feb 2019 01:27:49 +0000 (-0500) Subject: fixing the main content with two class attributes, fixing the excerpt function X-Git-Tag: v1.0.33^2~9 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=5f7b1f97e148ab9953bfaa7d50c7dcf677dda298;p=WP-Themes%2Fvisitbenzie.git fixing the main content with two class attributes, fixing the excerpt function --- diff --git a/functions.php b/functions.php index e95ab02..82da8ae 100644 --- a/functions.php +++ b/functions.php @@ -224,28 +224,25 @@ function blog_feed($category='',$limit=1){ endif; echo "

$post->post_title

"; echo "
"; - echo "
". content_excerpt($post->post_content, 30)."
"; + echo "
". content_excerpt($post->ID, 30)."
"; } $output = ob_get_contents(); ob_end_clean(); return $output; } -/* Returns the first $wordsreturned out of $string. If string -contains fewer words than $wordsreturned, the entire string -is returned. -*/ -function content_excerpt($string, $wordsreturned){ - $excerpt = $string; // Just in case of a problem - - $array = explode(" ", $string); - /* Already short enough, return the whole thing - */ - if (count($array)<=$wordsreturned){ - $excerpt = $string; - }else{ - array_splice($array, $wordsreturned); - $excerpt = implode(" ", $array)." ..."; - } - return $excerpt; +function content_excerpt($post_id, $count = 50){ + $the_post = get_post($post_id); //Gets post ID + $the_excerpt = ($the_post ? $the_post->post_content : null); //Gets post_content to be used as a basis for the excerpt + $excerpt_length = $count; //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; + + return $the_excerpt; } \ No newline at end of file diff --git a/parts/main-content.php b/parts/main-content.php index e604334..58dcaac 100644 --- a/parts/main-content.php +++ b/parts/main-content.php @@ -1,4 +1,4 @@ -
+