WordPress.org

Forums

[resolved] Last posts problem (3 posts)

  1. metalvalley
    Member
    Posted 8 years ago #

    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?

  2. moshu
    Member
    Posted 8 years ago #

  3. metalvalley
    Member
    Posted 8 years ago #

    Thanks! Worked perfect!

Topic Closed

This topic has been closed to new replies.

About this Topic