fixing the main content with two class attributes, fixing the excerpt function
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 11 Feb 2019 01:27:49 +0000 (20:27 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 11 Feb 2019 01:27:49 +0000 (20:27 -0500)
functions.php
parts/main-content.php

index e95ab02..82da8ae 100644 (file)
@@ -224,28 +224,25 @@ function blog_feed($category='',$limit=1){
         endif;
         echo "<div class='blog-excerpt-title'><h4>$post->post_title</h4></div>";
         echo "<div class='blog-excerpt-image-container'><img src='$image[0]'/></div>";
-        echo "<div class='blog-excerpt-content'>". content_excerpt($post->post_content, 30)."</div>";
+        echo "<div class='blog-excerpt-content'>". content_excerpt($post->ID, 30)."</div>";
     }
         $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
index e604334..58dcaac 100644 (file)
@@ -1,4 +1,4 @@
-            <div id="main-content" class="small-12 columns" class="main-content">
+            <div id="main-content" class="small-12 columns main-content">
                 <?php if(have_posts()) : while(have_posts()): the_post();?>
                 <?php the_content();?>
                 <?php endwhile; else:?>