Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Display date in recent post function

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #33369
    rjmccollam
    Participant

    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

    #82826
    TheDoc
    Member

    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.