I am trying to figure out how to add a custom field to display an image instead of a title on the stats_get_csv from WordPress stats.
<?php if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv('postviews', 'days=2&limit=6') ) : ?>
<ol>
<?php foreach ( $top_posts as $p ) : ?>
<li><a href="<?php echo $p['post_permalink']; ?>"><?php echo $p['post_title']; ?></a></li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
Update
<?php if ( function_exists('stats_get_csv') && $top_posts = stats_get_csv('postviews', 'days=2&limit=6') ) : ?>
<?php if ( get_post_meta($post->ID, 'Image', true) ) : ?>
<ol>
<?php foreach ( $top_posts as $p ) : ?>
<li>
<img class="thumb" src="<?php echo get_post_meta($post->ID, 'Image', true) ?>" alt="<?php the_title(); ?>" height='100' width='100' />
</li>
<?php endforeach; ?>
</ol>
<?php endif; ?>
<?php endif; ?>
Return of that function should have post ID, right? Then it’s straight
get_post_meta()
using that ID and name of your field.Update
In your second code snippet
$post
is global variable,$post->ID
is not tied in any way with return ofstats_get_csv()
function. You need something like from first example ($p['post_permalink']
), just figure out if there is a field with ID.Also you don’t need wrapping
if ( get_post_meta($post->ID, 'Image', true) )
that would make sense only for single current post, not for loop of posts.