Forums

Configuring home page to only display specific # of stories and lines of text (6 posts)

  1. stanwelks
    Member
    Posted 2 years ago #

    1.) How do you configure it so it only show a specific # of lines of text on the home page for each story before the user has to click over to read the rest of the story?

    2.) How do you configure it so the home page only displays a specific # of stories?

    Thanks.

  2. blondishnet
    Member
    Posted 2 years ago #

    The thing is...it is not by lines... but by words

    1. Go to formatting.php in the wp-includes folder

    2. Look for the group of code as

    function wp_trim_excerpt($text) {
    	if ( '' == $text ) {
    		$text = get_the_content('');
    
    		$text = strip_shortcodes( $text );
    
    		$text = apply_filters('the_content', $text);
    		$text = str_replace(']]>', ']]>', $text);
    		$text = strip_tags($text);
    		$excerpt_length = apply_filters('excerpt_length', 55);
    		$words = explode(' ', $text, $excerpt_length + 1);
    		if (count($words) > $excerpt_length) {
    			array_pop($words);
    			array_push($words, '[...]');
    			$text = implode(' ', $words);
    		}
    	}
    	return $text;
    }

    3. If you see $excerpt_length = apply_filters('excerpt_length', 55); , change the text length which by default is 55 to the number of words you prefer.

  3. stanwelks
    Member
    Posted 2 years ago #

    Hi blondishnet,

    Thank you for your reply!

    How do I also adjust the number of stories that will appear on the home page before the user has to click a link to review more stories?

    Thanks!!!!

  4. buddha trance
    Member
    Posted 2 years ago #

    By changing a file in the wp-includes folder, you have to remember to make the change every time you upgrade WP.

    To determine the number of posts to be shown you go to your Admin Dashboard --> Settings --> Reading --> Blog pages show at most [# of] posts

    To select the number of words to be shown for the excerpt, I am using the Excerpt Editor plugin.

    Or you can insert the <!--more--> tag where desired, within the post.

  5. blondishnet
    Member
    Posted 2 years ago #

    You can adjust the amount in your Settings> Reading I believe. You can denote how many posts are readable. Also, you can specify if you want to show excerpts or full posts.

    Plugins are great to use, but I do not recommend using plugins for just about everything.

    It is true when you upgrade, you will have to adjust your formatting.php file to change your WordPress excerpt, but installing a plugin for this is just a waste of diskspace.

  6. buddha trance
    Member
    Posted 2 years ago #

    I have just found a thread with a suggestion from "doodlebee" that makes it possible to change the length of the excerpt by adding code to functions.php of the theme, rather than editing core files. This keeps any WP upgrading worry free. Just tested it, and it works. A great solution to keep in mind! I will use it myself and streamline on the number of plugins.
    http://wordpress.org/support/topic/301690?replies=2

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.