• Resolved pvalure

    (@pvalure)


    I want to show the latest three (3) posts on the home page (a static) as teasers to the blog/news page. I have the code below, modified to look ok, but I can’t pull in the post_date and author above the title. Any help?

    <?php $how_many=3; //How many posts do you want to show
    require_once('wp-config.php'); // Change this for your path to wp-config.php file&nbsp;?>
    <h1>Latest News</h1>
    
    <?php
    $news=$wpdb->get_results("SELECT <code>post_date</code>, <code>ID</code>,<code>post_title</code> FROM $wpdb->posts
    WHERE <code>post_type</code>=\"post\" AND <code>post_status</code>=\"publish\" ORDER BY post_date DESC LIMIT $how_many");
    foreach($news as $np){
    printf ("<ul>",$np->post_date);
    printf ("<li class=\"latest-news\"><a href=\"index.php?p=%s\">%s</a></li>", $np->ID,$np->post_title, "</ul>");
    }?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • just use this plugin
    https://aralbalkan.com/1016

    Thread Starter pvalure

    (@pvalure)

    I was really hoping to get the code working. I don’t want a client to have to manually update which posts are supposed to show on the home page.

    Thread Starter pvalure

    (@pvalure)

    So I solved the problem on how to automate the titles for my client with this code:

    <h1>Latest News</h1>
    <ul class="latest-news">
    <?php
     global $post;
     $myposts = get_posts('numberposts=3');
     foreach($myposts as $post) :
     ?>
        <li><span class="post-info"><?php the_time('F jS, Y'); ?></span><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
     <?php endforeach; ?>
    </ul>

    Thanks for the suggestion samboll, I might be able to use that plugin in the future.

    eivindvr

    (@eivindvr)

    Ah pvalure! works like a charm!
    just what I need!

    thank you for this useful code share!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘I want to include a few latest post titles, date and author on the home (page)’ is closed to new replies.