Forums

[resolved] Display first 25 words of excerpt on index page (19 posts)

  1. hampusjageland
    Member
    Posted 3 years ago #

    My work in progress website is http://www.projektblog.info.

    I want to display only the first 25 words (or 4 lines or first paragraph) of the excerpt text on the first page.

    Does anyone know how to do this?

    Current code is:

    <?php the_excerpt(); ?>

    Appreciate your help!
    Hampus

  2. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    Try this page in the codex for more information:
    http://codex.wordpress.org/Template_Tags/the_excerpt

    Read the short section on: Control Excerpt Length using Filters

  3. hampusjageland
    Member
    Posted 3 years ago #

    Tried inserting

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

    in my functions file but it only leaves me with a error message...

    I guess this adjusts the length of the excerpts wherever it is. The thing is that I want it to display the whole excerpts on the single post and on the index page only a few lines.

  4. jonimueller
    Member
    Posted 3 years ago #

  5. hampusjageland
    Member
    Posted 3 years ago #

    That link doesn't work for some reason, can't even go onto wptricks.net...

  6. Mark
    Member
    Posted 3 years ago #

    If you're looking for various length excerpts on various templates, then I'd suggest you use a plugin:

    Kaf's plugin "The Excerpt Reloaded" has been a favorite of mine for a long time and lets you change the length of the excerpt as & when you need it:

    <?php wp_the_excerpt_reloaded('excerpt_length=24'); ?>

    Easypeasy :)

  7. hampusjageland
    Member
    Posted 3 years ago #

    Thanks YellowLlama!

    The only problem is that I currently can use plugins since I'm not able to access and edit any files through wordpress for some reason. So I have to do everything manually over the ftp. I can still activate plugins so if it's fairly easy to edit the settings in the php file then I could give it a try.

    I managed to shorten the copy for the index page now, the problem is that it's still shortened in the single post page...

  8. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    You may need to address this first:

    ... I'm not able to access and edit any files through wordpress for some reason. So I have to do everything manually over the ftp.

    ... and there are numerous issues recognized at the W3C Markup Validator that may need addressing as well.

    Once addressed it may be a lot easier to sort out the excerpt.

  9. hampusjageland
    Member
    Posted 3 years ago #

    Woo, never seen that before.
    I'll try and sort it all out. Mostly tiny things it seems but still...

  10. hampusjageland
    Member
    Posted 3 years ago #

    Fixed most of it now. It really doesn't seem to like my

    <hr align="left" color= #A7A9AC size="1" width="240"/>

    nor my

    <h8><?php the_title(); ?></h8>

    Should those <hr> be given a style through CSS instead?
    And the style of the title is probably set somewhere else? I just connected it to the css <h8>

  11. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    I would use CSS to style the <hr> myself, or create an hr class and use it instead of the inline properties.

    ... and there is no <h8> tag, see this article: http://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.5

  12. hampusjageland
    Member
    Posted 3 years ago #

    The only thing left to do is to sort out how to get the full excerpt on the single post pages. Any suggestions? After that's solved, the website it finished!

    This is what I use at the moment to strip back the excerpt on the index page:

    function my_excerpt_length($text){
    return 19;
    }
    add_filter('excerpt_length', 'my_excerpt_length');
    
    function new_excerpt_more($more) {
    	return '...';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    and applied using in index and single post pages:

    <?php the_excerpt(); ?>

    Thanks heaps for your help!
    Hampus

  13. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    In single.php, use <?php the_content();?>. You shouldn't need to do anything else.

  14. hampusjageland
    Member
    Posted 3 years ago #

    That pulls in all the images as well though.

    I use image grabber to not display the first image in the post (which is the thumbnail).

    <?php images('2'); ?>
    <?php images('3'); ?>
    <?php images('4'); ?>
    <?php images('5'); ?>

    and so on...

    Is there another way then to not display the thumbnail?
    Everything works perfectly at the moment so if there's an easy way of getting the full excerpt, that would be good!

    Thanks!

  15. hampusjageland
    Member
    Posted 3 years ago #

    The problem is also that I currently display the images in one <td> and the copy in another. That's the only way I can think of that displays the text next to the image.

    So I pretty much use:

    <td>
    <?php images('2'); ?>
    </td>
    <td>
    <?php the_excerpt(); ?>
    </td>

    For that reason I can't use <?php the_content();?> since that would display the whole post, with images a second time.

    If there's a way of displaying the images with the text right next to it, as currenly designed, please let me know!

    If anyone has got any other suggestion on how to get all excerpt in the single post and not in the index page, I'd really appreciate your help!

    Thanks,
    H

  16. hampusjageland
    Member
    Posted 3 years ago #

    Has anyone got any suggestions?

    Cheers,
    H

  17. hampusjageland
    Member
    Posted 3 years ago #

    Has anyone got any suggestions on how to make a post look like it currently does but without using

    <td>
    <?php images('2'); ?>
    </td>
    <td>
    <?php the_excerpt(); ?>
    </td>

    which I currently use?
    I want to pull the whole post in, not only the excerpt but still make it look like it does.

    http://www.projektblog.info

    thank you!

  18. jessesmt
    Member
    Posted 2 years ago #

    thanks for hampusjageland's post, it helped me on my site tweetsnews.net.

  19. samuel8gage
    Member
    Posted 2 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic