• Resolved hampusjageland

    (@hampusjageland)


    My work in progress website is https://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

Viewing 15 replies - 1 through 15 (of 18 total)
  • Try this page in the codex for more information:
    https://codex.www.ads-software.com/Template_Tags/the_excerpt

    Read the short section on: Control Excerpt Length using Filters

    Thread Starter hampusjageland

    (@hampusjageland)

    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.

    Thread Starter hampusjageland

    (@hampusjageland)

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

    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 ??

    Thread Starter hampusjageland

    (@hampusjageland)

    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…

    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.

    Thread Starter hampusjageland

    (@hampusjageland)

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

    Thread Starter hampusjageland

    (@hampusjageland)

    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>

    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: https://www.w3.org/TR/REC-html40/struct/global.html#h-7.5.5

    Thread Starter hampusjageland

    (@hampusjageland)

    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

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

    Thread Starter hampusjageland

    (@hampusjageland)

    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!

    Thread Starter hampusjageland

    (@hampusjageland)

    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

    Thread Starter hampusjageland

    (@hampusjageland)

    Has anyone got any suggestions?

    Cheers,
    H

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Display first 25 words of excerpt on index page’ is closed to new replies.