pvalure
Member
Posted 2 years ago #
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 ?>
<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>");
}?>
pvalure
Member
Posted 2 years ago #
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.
pvalure
Member
Posted 2 years ago #
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
Member
Posted 2 years ago #
Ah pvalure! works like a charm!
just what I need!
Athrill
Member
Posted 2 years ago #
thank you for this useful code share!