Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Popular Post Image Display with text help me!

Hi I have a wordpress theme I'm designing and I have a popular post section in my footer. I've used the following code to generate popular post to be displayed by number of comments (which seems to be working fine). However I also want an image from that popular post to display above the post title any ideas on how to achieve this?

<?php
$pop_posts = query_posts('orderby=comment_count&posts_per_page=4');

    foreach( $pop_posts as $post ) {  
        $custom_image = get_post_custom_values('the_title', $post->ID);  
        $image = $custom_image[0] ? $custom_image[0] : get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);  
        printf('<li><a href="%s" title="%s"><img src="%s" alt="%s" /></a></li>', get_permalink($post->ID), $post->post_title, $image, $post->                           post_title);  


    }  
    ?>

3 Answers

Matt Campbell
Matt Campbell
9,767 Points

I'm not sure why you're writing the code you've written. All you need to to do is ask for the image in the loop. Have a read of the codex.

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Hi! Were you able to get this resolved?

Hi @Zacgordon, I think I figured it out. But the slider is causing the site to load a lot slower any idea on how to fix that

Hi @Zacgordon, I think I figured it out. But the slider is causing the site to load a lot slower any idea on how to fix that