• How can I make it so only excerpts of posts appear on my main page? Currently the whole blog post is on display. I only want part of it on the main page.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @dgraham4,

    To display excerpts of posts on home page instead of whole blog post change the following code in the below listed template files in your child theme of Twenty Fourteen theme.

    Before Editing:

    the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ) );

    After Editing:

    if (is_home() ) {
    	the_excerpt();
    } else {
    	the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyfourteen' ) );
    }

    Template files to be edited in the child theme:
    content.php
    content-video.php
    content-quote.php
    content-page.php
    content-link.php
    content-image.php
    content-gallery.php
    content-audio.php
    content-aside.php

    Best Regards,
    WPMU DEV

    If you want using excerpt by change functions.php file because don’t want use too many file in child theme. You can use this code. This is the code i’m using in my blog.

    function my_excerpts($content = false) {
    
    // If is the home page, an archive, or search results
        if(is_home() || is_archive() || is_search()) :
            global $post;
        		$content = $post->post_excerpt;
       		$content = strip_shortcodes($content);
       		$content = str_replace(']]>', ']]>', $content);
        		$content = preg_replace("/<img[^>]+\>/i", "", $content);
        		$content = strip_tags($content, '<p>');
    
    	// If an excerpt is set in the Optional Excerpt box
        if($content) :
            	$content = apply_filters('the_excerpt', $content);
    
    	// If no excerpt is set
    		else :
            		$content = $post->post_content;
            		$content = strip_shortcodes($content);
    			$content = str_replace(']]>', ']]>', $content);
            		$content = preg_replace("/<img[^>]+\>/i", "", $content);
            		$content = strip_tags($content, '<p>');
            		$excerpt_length = 65;
            		$words = explode(' ', $content, $excerpt_length + 1);
    				if(count($words) > $excerpt_length) :
            				array_pop($words);
           					array_push($words, '[...]');
            				$content = implode(' ', $words);
        				endif;
       			 $content = '<p>' . $content . '</p>';;
    
        	endif;
        endif;
    
    // Make sure to return the content
    	return $content;
    
    }
    
    // Add filter to the_content
    	add_filter('the_content', 'my_excerpts');

    Best Regards,
    Naziman Azlye

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excerpts Instead of Whole Post’ is closed to new replies.