List of recent posts and adding the first post with the excerpt
-
Hello, What I like is this:
A list of recent posts, with date, nr of comments and a link to the post.
This is the code for this to happen:
<?php
$today = current_time('mysql', 1);function truncate($string,$chars,$append = '...') {
if(strlen($string) > $chars) {
$string = substr($string, 0, $chars);
$trunc_at = strrpos($string, ' ');if($trunc_at !== FALSE)
$string = substr($string, 0, $trunc_at);
$string = $string.$append;
}return $string;
}if ( $recentposts = $wpdb->get_results("SELECT ID, post_title, post_date FROM dotenel_posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 20")):
?><?php
foreach ($recentposts as $post) {
if ($post->post_title == '')
$post->post_title = sprintf(__('Post #%s'), $post->ID);$posttime = strtotime($post->post_date);
$mytime = date('<font color="red">H:i</font>', $posttime);
$mydate = date('<font color="red">d/m</font>', $posttime);
$currtime = time();
$today = date('d',$currtime);
$postday = date('d',$posttime);
if($postday==$today)
echo $mytime;
else
echo $mydate;echo " ID'>";
$shorten_title = truncate($post->post_title, 45);
echo $shorten_title;
echo '';$numcomments = $wpdb->get_var("SELECT COUNT(*) FROM dotenel_comments WHERE comment_post_ID = '{$post->ID}' AND comment_approved = '1'");
echo " <small>reactie(s): {$numcomments}</small>
";}
?><?php endif; ?>
What I’d like to add is that the latest post to have a excerpt and a (read more) link and the rest just listed.
Is that possible?
To view an example of what I mean is https://www.nu.nl/
- The topic ‘List of recent posts and adding the first post with the excerpt’ is closed to new replies.