Category Image in last 10 posts
-
This is my website:
https://frontpage.klifix.nl/In the sidebar you see the last x posts with the date or time and the nr of comments listed with a truncatefunction.
I’d like to at an icon to each of these posts showing in which category it is posted in. Similar to this website:
https://games.fok.nl/Currently I use this code:
<?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 25")): ?> <?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 " <a href='https://frontpage.klifix.nl/?p=$post->ID'>"; $shorten_title = truncate($post->post_title, 45); echo $shorten_title; echo '</a>'; $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM dotenel_comments WHERE comment_post_ID = '{$post->ID}' AND comment_approved = '1'"); echo " ({$numcomments})<br />"; } ?> <?php endif; ?>
What code do I have to add to this code to show a category-image?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Category Image in last 10 posts’ is closed to new replies.