Grow your CSS skills. Land your dream job.

Display date in recent post function

  • # July 4, 2011 at 4:38 pm

    I am using the Recent Posts Function from the Snippets section of CSS-Tricks, and it is working great, but how do I add the date into the mix?

    The function:

    function recent_posts($no_posts = 10, $excerpts = true) {

    global $wpdb;

    $request = "SELECT ID, post_title, post_excerpt FROM $wpdb->posts WHERE post_status = 'publish' AND post_type='post' ORDER BY post_date DESC LIMIT $no_posts";

    $posts = $wpdb->get_results($request);

    if($posts) {

    foreach ($posts as $posts) {
    $post_title = stripslashes($posts->post_title);
    $permalink = get_permalink($posts->ID);

    $output .= '

    ' . htmlspecialchars($post_title) . '

    ';

    if($excerpts) {
    $output.= '

    ' . stripslashes($posts->post_excerpt) . '

    ';
    }

    $output .= 'Read More
    ';
    }

    } else {
    $output .= '
  • No posts found
  • ';
    }

    echo $output;

    Thanks

    # July 4, 2011 at 5:03 pm

    I’m not sure if this will work, but it’d be my first guess. I’m only posting the foreach section since it’s the only thing relevant:

    foreach ($posts as $posts) {
    $post_title = stripslashes($posts->post_title);
    $permalink = get_permalink($posts->ID);
    $thedate = get_the_date($posts->ID);

    $output .= '

    ' . htmlspecialchars($post_title) . '

    ';

    $output .='

    ' . $thedate . '

    ';

    if($excerpts) {
    $output.= '

    ' . stripslashes($posts->post_excerpt) . '

    ';
    }

    $output .= 'Read More
    ';
    }
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".