• Hi folks,

    I’m working on a new site where part of one (long) page is being displayed on the homepage and I’d like to use the excerpt to cut it off after so many words before having it display a “continue reading…” link.

    Now, I know how to change the length of the excerpt on a site wide basis and that’s all good, but in this one instance I’d like to make it longer, is this possible?

    Cheers,
    Rab

Viewing 8 replies - 1 through 8 (of 8 total)
  • You may be able to do something like this (but I haven’t tested it to see if it will actually work):

    function custom_excerpt_length( $length ) {
       if ( is_page( /*Page ID goes here*/ ) ) {
          return 20;
       }
    }
    add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

    Thread Starter RSimpson

    (@rsimpson)

    Hi JPry,

    Would the page ID I’m testing for be the page the post appears on or the page I want to change the excerpt length on?

    Cheers,
    Rab

    nickaster

    (@nickaster)

    Hi guys – I’m trying to do the same thing… isn’t there a way to do this and avoid messing with functions.php alltogether?

    ie – can’t you just say “display first XX words of the excerpt here” and be done with it?

    Thread Starter RSimpson

    (@rsimpson)

    *bump*

    Michael

    (@alchymyth)

    I’m working on a new site where part of one (long) page is being displayed on the homepage and I’d like to use the excerpt to cut it off after so many words before having it display a “continue reading…” link.

    page as in ‘static page’ ?

    excerpts don’t really work with pages.

    you could try <!--nextpage--> instead.
    http://codex.wordpress.org/Styling_Page-Links

    or add the filter function and call into the template before the loop(instead of into functions.php)
    i have not widely tried it, but it seems possible.

    <?php	function excerpt_length_for_template($length) {
    	return 5;
    }
    add_filter('excerpt_length', 'excerpt_length_for_template');
    ?>
    Thread Starter RSimpson

    (@rsimpson)

    If excerpts don’t work well with static pages, could I load it in with the_content(), trim the number of words and add a continue link to the end?

    Michael

    (@alchymyth)

    not sure, because the continue link would point to the same page which would only show the short form – kind of catch-22

    (i tried to overcome this by checking the referring link url:
    http://codex.wordpress.org/Function_Reference/wp_get_referer
    and just using the last part after the / )

    a possible hack is here:
    in page.php (or your page template) replace <?php the_content(); ?> with:
    http://pastebin.com/y0C0569V

    (not widely tested at all;
    does not work together with <!--nextpage-->

    edit:
    fix for that: http://pastebin.com/WSyXCJAy )

    Michael

    (@alchymyth)

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘custom length excerpt in one template only’ is closed to new replies.