Modifying the excerpt on a post list page

Community Forums Forums Design Tips and Tricks Modifying the excerpt on a post list page

This topic is: resolved

Tagged: ,

This topic contains 6 replies, has 2 voices, and was last updated by  Chris Cree 1 year, 7 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #9809

    theMikeD
    Participant
    Post count: 20

    By default, home.php displays the excerpt for a post and the featured image. How can I add something to the beginning of the excerpt text? Specifically, I’d like the date of the post to show up as in an old-skool newspaper byline. For example:

    “7 May 2012 – Lorum ipsum….”

    Is there a filter or something I can use? I don’t see anything appropriate listed in the filter reference.

    #9835

    Chris Cree
    Participant
    Post count: 147

    You can do that with a combination of modifying the post info section and css. If you use the Simple Edits plugin you can use this shortcode in the post info section:
    [html] [post_date format="j F Y" after=" - "] [/html]

    Then you can just use the appropriate CSS to position that at the beginning of the first paragraph of text.

    Edit: I missed that you are asking about the excerpt. It might be easier for you to use manual excerpts and add the date to the excerpt field.


    #9848

    theMikeD
    Participant
    Post count: 20

    Geez, I hope not! There must be a way to filter the excerpt and insert the date in there!

    #9853

    Chris Cree
    Participant
    Post count: 147

    Genesis uses the WordPress function the_excerpt() for excerpts. I don’t see a filter listed for the excerpt content itself. But if you research it you may find someone who has done it already.

    Short of that, I’d try my initial suggestion about changing the post info and use the content limit instead on your home page.


    #9858

    theMikeD
    Participant
    Post count: 20

    function md_add_dateline( $content ) {
    return “HELLO”;
    }
    add_filter( ‘the_excerpt ‘, ‘md_add_dateline’);

     

    According to the docs, that should filter the excerpt and replace it with “HELLOO” but it does not. But once I figure it out, I think that’ll be the way to go.

    #9860

    theMikeD
    Participant
    Post count: 20

    Ahh, an extra space killed me. This code does the trick:


    function md_add_dateline( $content ) {
    $d = the_date('',"", ": ", true);
    return str_replace ('',$p, $content);
    }
    add_filter( 'the_excerpt', 'md_add_dateline');

     

    #9882

    Chris Cree
    Participant
    Post count: 147

    Sweet. Glad you were able to get it sorted.


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.