Skip to:
Content
Pages
Categories
Search
Top
Bottom

Featured Posts on main blog

  • @romik84

    Member

    Hi,

    I just try to write a function to show top posts on the main blog but it doesn’t work. What am I doing wrong? Here is the code.

    function featured_posts() {

    global $wpdb;

    $date = date('Y-m-d', strtotime('-1 months'));
    $date2 = date('Y-m-d', strtotime('-1000 days'));
    $days = (strtotime($date2) - strtotime($date)) / (60 * 60 * 24);
    $duration = $days;

    $request = "SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments";
    $request .= " WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish'";
    if(!$show_pass_post) $request .= " AND post_password =''";
    if($duration !="") $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date ";
    $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $popularpostnumber";
    $posts = $wpdb->get_results($wpdb->prepare($request));
    if ($posts):
    echo '

      ';
      foreach ($posts as $post):
      setup_postdata($post);
      $post_title = stripslashes($post->post_title);
      $comment_count = $post->comment_count;
      $permalink = get_permalink($post->ID);
      echo '

    • ' . $post_title . ' (' . $comment_count.')
    • ';
      endforeach;
      echo '

    ';
    else:
    _e("Didn't find any featured posts");
    endif;

    }

    thanks for help if any :)

  • The topic ‘Featured Posts on main blog’ is closed to new replies.
Skip to toolbar