Title: Last posts problem
Last modified: August 18, 2016

---

# Last posts problem

 *  Resolved [metalvalley](https://wordpress.org/support/users/metalvalley/)
 * (@metalvalley)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/last-posts-problem-2/)
 * I currently use WP 2.x
 * To get the last posts, time/date and nr of comments 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 gibson_posts WHERE post_status = 'publish' AND post_date_gmt < '$today' ORDER BY post_date DESC LIMIT 50")): ?><?php foreach ($recentposts as $post) { if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
       $posttime = strtotime($post->post_date);
       $mytime = date('H:i', $posttime);
       $mydate = date('d/m', $posttime);
       $currtime = time();
       $today = date('d',$currtime);
       $postday = date('d',$posttime);
       if($postday==$today)
       echo $mytime;
       else
       echo $mydate;
       echo " <a href='http://www.metalvalley.nl/nieuws/$post->ID/'>";
         $shorten_title = truncate($post->post_title, 26);
       echo $shorten_title;
         echo '</a>';
       $numcomments = $wpdb->get_var("SELECT COUNT(*) FROM gibson_comments WHERE  comment_post_ID = '{$post->ID}' AND comment_approved = '1'");
       echo " ({$numcomments})<br />"; } ?>
       <?php endif; ?>
       ```
   
 * This code takes al the titles of the last posts, date/time and nr of comments.
   On older versions it worked perfect, but with the newer WP versions (2.x) it 
   also takes titles of the last pages, so pages and posts. How can I exclude pagetitles
   from this list?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/last-posts-problem-2/#post-568903)
 * [http://wordpress.org/support/topic/102028?replies=1](http://wordpress.org/support/topic/102028?replies=1)
 *  Thread Starter [metalvalley](https://wordpress.org/support/users/metalvalley/)
 * (@metalvalley)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/last-posts-problem-2/#post-569202)
 * Thanks! Worked perfect!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Last posts problem’ is closed to new replies.

## Tags

 * [last](https://wordpress.org/support/topic-tag/last/)
 * [page](https://wordpress.org/support/topic-tag/page/)
 * [post](https://wordpress.org/support/topic-tag/post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [metalvalley](https://wordpress.org/support/users/metalvalley/)
 * Last activity: [18 years, 10 months ago](https://wordpress.org/support/topic/last-posts-problem-2/#post-569202)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
