• Hello,

    I’m having a problem getting excerpts to work for me. Specifically, the length and a carriage return. My understanding is the default action of Excerpt is it will pull the first 55 words – but for some reason – I’m getting the entire excerpt. Also, there’s some strange carriage return at the end of the content that isn’t in the excerpt itself. This doesn’t occur when the IF statement below uses the_content().

    In short, I’m simply trying to test is the except is blank – if it is – use the content – if not – use the excerpt.

    //check to see if excerpt is blank – if not use it, else use post content
    if($post->post_excerpt != “”) {
    $rcsample = the_excerpt();
    } else {
    $rcsample = get_the_content();
    }
    // Remove extraneous stuff from the content text
    $rcstthec = strip_tags($rcsample);
    $rcsspthec = str_replace(‘ ‘,’ ‘,$rcstthec );
    $rcsspthec = preg_replace( ‘|\[(.+?)\](.+?\[/\\1\])?|s’, ”, $rcsspthec );

    if(strlen($rcsspthec) > 155)
    {
    $newrcs=LimitText(trim($rcsspthec),10,155,””);
    echo “<p>$newrcs”;
    ?>
    <?php
    }
    else
    {
    $newrcs=$rcsspthec;
    echo “<p>$newrcs”;
    }
    ?>
    …….

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi d4jaj1,

    In order to set the length of any excerpts on your pages, you need to add some lines into the file “functions.php” located into your plugin folder:

    function new_excerpt_length($length) {
    return 55;
    }
    add_filter(‘excerpt_length’, ‘new_excerpt_length’);

    Bye bye and happy blogging

    Thread Starter d4jaj1

    (@d4jaj1)

    Yea, I’d tried that from the codex area – but it doesn’t work. I changed the return to 10 and it made no difference.

    Try to save that piece of code into a php file and name it newExcerptLength.php

    <?php
    /*
    Plugin Name: New Excerpt Lenght
    Description: This plugin change the excerpt length to 55 characters
    Version: 0.1
    Author: Some Guy from Mars
    */
    
    function new_excerpt_length($length) {
    return 55;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    ?>

    Ow, and put that file into your plugin folder ??

    Thread Starter d4jaj1

    (@d4jaj1)

    I’m sorry this just doesn’t work for me – the function simply returns the the length. What I need is the code to pass the_excerpt to function and have the actual text from the excerpt returned up to a maximum number of words or characters

    Original Excerpt
    One two three four five six seven

    Return Max Three Words Function
    One Two Three

    How can I do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Help With Excerpt’ is closed to new replies.