WordPress.org

Ready to get started?Download WordPress

Forums

Changing Excerpt Length (20 posts)

  1. zubair04
    Member
    Posted 2 years ago #

    Hi,

    Im trying to change the excerpt length shown in the post previews on the homepage. the loop php file is currently outputting 'the_excerpt();' in order to get the default output.

    i have tried a few plugins, recommended functions to function.php and even modify the core file in wp-include, but everytime i get the same results - which is no change.

    could anyone give me a hand with this ?

    thank you

  2. Digital Raindrops
    Member
    Posted 2 years ago #

    This will really depend on your theme, so which theme are you using would be a start, if it is a well known or free theme then it will be easier to answer?

    The standard code should work, if it is not then it is likely your theme is changing it back somewhere else in the code.

    Regards

    David

  3. zubair04
    Member
    Posted 2 years ago #

    hi,

    Im using the twentyten theme, the basic theme that came with the wordpress package, but i have edited the styling quite a bit.

  4. Aboobacker P
    Member
    Posted 2 years ago #

    Add the below code in your functions.php

    function new_excerpt_length($length) {
        return 200;
    }
    add_filter('excerpt_length', 'new_excerpt_length');

    Increase the count as per your wish.

  5. zubair04
    Member
    Posted 2 years ago #

    Hi, thanks for the help,

    ive tried adding this , and other similar functions but to no avail.

  6. alchymyth
    Forum Moderator
    Posted 2 years ago #

    if you are editing twenty ten directly, then the excerpt length is set in functions.php:

    function twentyten_excerpt_length( $length ) {
    	return 40;
    }
    add_filter( 'excerpt_length', 'twentyten_excerpt_length' );
  7. Digital Raindrops
    Member
    Posted 2 years ago #

    Are you using a child theme or the twenty ten theme?

    You should really be using a child theme then this would go in the after_setup_theme hook!

    In twenty ten you already have the function

    function twentyten_excerpt_length( $length ) {
    	return 40;
    }
    add_filter( 'excerpt_length', 'twentyten_excerpt_length' );

    * To override this length in a child theme, remove the filter and add your own
    * function tied to the excerpt_length filter hook.

    So you could code:

    remove_filter( 'excerpt_length', 'twentyten_excerpt_length' );
    
    function my_twentyten_excerpt_length( $length ) {
    	return 50;
    }
    add_filter( 'excerpt_length', 'my_twentyten_excerpt_length' );

    HTH

    David

  8. zubair04
    Member
    Posted 2 years ago #

    ive tried editing the return figure around line 231 in my functions.php file in theme/twentyten but still no luck :(

  9. zubair04
    Member
    Posted 2 years ago #

    i dont think im using a child theme, i have just been editing the php/css files in the twentyten theme folder, i will now try the suggestion from David

  10. zubair04
    Member
    Posted 2 years ago #

    Ive tried davids code but it has not worked.

    http://thecypher.co.uk

    this is the site im working on. at the minute i am using a plugin which generates a thumbnail from the image in a post. im just wondering if that has anything to do with it ?

    thanks

  11. Digital Raindrops
    Member
    Posted 2 years ago #

    Trial and error!

    Something is changing it as the word count is 56, the theme is set at 40, deactivate the plugins and count the words in the excerpt, change the value and try again, them reactivate the plugins one at a time and see if it goes back to 56.

    HTH

    David

  12. zubair04
    Member
    Posted 2 years ago #

    ah okay so it must be a plugin thats overriding the theme,

    il try disabling each plugin and see what happens.

    thanks for your help

  13. zubair04
    Member
    Posted 2 years ago #

    ok so when i deactivate the 'thumbnail for excerpts' plugin . the site shows the full post including the large image and the full text.

    so its definitely to do with this plugin, unfortunatley the settings for this plugin does not have an option to edit the excerpt length...

  14. zubair04
    Member
    Posted 2 years ago #

    thanks for your help everyone , the problem was in the php file provided by this plugin , at the bottom was a function where it redefined teh excerpt length

  15. Joseph Shaw
    Member
    Posted 2 years ago #

    Grats! I hate it when plugins do stuff like that!
    :-)

  16. Digital Raindrops
    Member
    Posted 2 years ago #

    thanks for your help everyone , the problem was in the php file provided by this plugin , at the bottom was a function where it redefined the excerpt length

    If the plugin is well supported might be worth contacting the author, tell them of the issue and they may add this as a setup option.

    It does not make a lot of sense to have set it 56 words only to pad it out to the image height, not considering different themes use different font sizes, and different languages use different word lengths, so it should be a set option, or left alone.

    Add the plugin name to the tags so others and maybe the author will be able to find this topic.

    David

  17. Digital Raindrops
    Member
    Posted 2 years ago #

    @zubair04

    B.T.W.
    The two column posts look great when the text is the same, create a post with different sizes of words and you might find that the posts get out of line.

    If you look at the page the two columns widths do not align with the header image, this is due to the right margin in the second column.

    [------Header-----]
    [Post 1]-[Post 2]-
    [Post 3]-[Post 4]-

    I use a different class for the left and right columns, and this makes the posts line up nice across the page and where the text is shorter or longer, clear both on the left and no margin on the right.

    .column-left{
    	clear: both;
    	float: left;
    	position: relative;
    	margin-right: 7.6%;
    	width: 46%;
    }
    
    .column-right{
    	float: left;
    	position: relative;
    	width: 46%;
    }

    Then in the content or loop I add a counter variable.

    <?php $counter = 0; ?>
    <?php while ( have_posts() ) : the_post(); ?>
    	<?php $counter++; //Increment the Counter ?>
    	<?php if($counter % 2) : ?>
    		<div  class="column-left">
    	<?php else: ?>
    		<div  class="column-right">
    	<?php endif; ?>	
    
    		<!-- Post Output Code Here -->
    
    		</div>
    <?php endwhile; ?>

    Just thought I would add this comment as you might want to revisit the layout with different content values.

    HTH

    David

  18. zubair04
    Member
    Posted 2 years ago #

    this is a problem that i was about to deal with next, as i put in a temporary measure to change to layout to this.

    thanks very much david for this code, i will try and implement this now and see how it works.

    much appreciated !

  19. zubair04
    Member
    Posted 2 years ago #

    ive tried implementing the code and if u visit the site , the posts are just repeated infinitely :|

    would anyone mind taking a look and see where im going wrong with this ?

    thanks again

  20. zubair04
    Member
    Posted 2 years ago #

    ...sorted out now.

    thanks everyone for your help, saved me a lot of time

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.