WordPress.org

Ready to get started?Download WordPress

Forums

Display Posts Shortcode
[resolved] show date in format: D/M/Y (4 posts)

  1. mrgoolie
    Member
    Posted 2 years ago #

    Hi,
    Does anybody know how to format the date so instead of M/D/Y you get D/M/Y:)

    http://wordpress.org/extend/plugins/display-posts-shortcode/

  2. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    You'll need to use the output filter to modify the date, as the format is not editable through the shortcode. Something like this would go in your functions.php file:

    https://gist.github.com/1303939

    More info on date formats

  3. keeters
    Member
    Posted 2 years ago #

    Bill, this is a great plug-in! There was a small error in your filter code, which i have updated below.

    add_filter( 'display_posts_shortcode_output', 'be_display_posts_date', 10, 7 );
    function be_display_posts_date( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    
    // Change the date
    if ( $atts['include_date'])
    $date = ' <span class="date">('. get_the_date('j/n/Y') .')</span>';
    else $date = '';
    
    // Now let's rebuild the output.
    $output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
    
    // Finally we'll return the modified output
    return $output;
    }
  4. Bill Erickson
    Member
    Plugin Author

    Posted 2 years ago #

    Good catch! Yeah, this code was untested so I just copied the date part directly out of the plugin. Since the attributes haven't been parsed yet, your approach is needed. I've updated the code.

    Another approach would be to check if( !empty( $date ) )

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic