WordPress.org

Ready to get started?Download WordPress

Forums

Including Thumbnails in stats_get_csv Results? (1 post)

  1. kevin_curry
    Member
    Posted 2 years ago #

    I need some help.

    So I'm using this code to return the top posts from my blog:

    <?php function get_stats_exclude_home($numDays,$numPosts) {
          $numPostsPlus = $numPosts + 1;
          $blnHasHome = false;
          $intRowsLoop = 0;
          $intRowFound;
          $intRowsCount;
          $most_read_posts;
    
          $strArgs = 'days=' . $numDays . '&limit=' . $numPostsPlus;
    
          if (function_exists('stats_get_csv')) {
            $most_read_posts = stats_get_csv('postviews', $strArgs);
          }
    
          foreach ($most_read_posts as $single_post) {
            $postTitle = $single_post['post_title'];
            if($postTitle == 'Home page') {
              $blnHasHome = true;
              $intRowFound = $intRowsLoop;
            }
            $intRowsLoop = $intRowsLoop + 1;
          }
    
          $intRowsCount = $intRowsLoop;
    
          if($blnHasHome) {
            unset($most_read_posts[$intRowFound]);
          } else {
            if($intRowsCount > $numPosts){
              unset($most_read_posts[$numPosts]);
            }
          }
    
          return $most_read_posts;
        } ?>

    And this code to display the results in my theme template:

    <?php if ( function_exists('get_stats_exclude_home') && $top_posts = get_stats_exclude_home(1,4) ) : ?>
    <?php foreach ( $top_posts as $p ) : ?>
    <div class="related">
            <a href="<?php echo $p['post_permalink']; ?>"><?php thumbnail(); ?></a>
            <p><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a></p>
    	</div>

    The problem I'm having is in trying to include post_thumbnail functionality.

    I believe something along these lines should work??:

    $post = get_post($p['post_id']);
    if ( !isset($post->post_type) || $post->post_type != 'post' )
        continue;
    if ( has_post_thumbnail( $post->ID ) )
        $thumbnail = get_the_post_thumbnail( $post->ID );
    else
        $thumbnail = '';

    Then I'm stuck on how to display the thumbnail? Any help is greatly appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic