Title: Featured posts code problem
Last modified: August 19, 2016

---

# Featured posts code problem

 *  [fangonk](https://wordpress.org/support/users/fangonk/)
 * (@fangonk)
 * [16 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-code-problem/)
 * Im new to WP and Im not real sure how to work with the loop. I am trying to display
   featured posts in the sidebar with this code:
 *     ```
       <?php
           query_posts('cat=5');
           $url = get_permalink();
           while(have_posts()){
           the_post();
           $image_tag = wp_get_post_image('return_html=true');
           $resized_img = getphpthumburl($image_tag,'h=168&w=168&zc=1'); 
   
           $title = $post->post_title;
   
           echo "<ul class='left_featured'>";
           echo "<li><a href='";
           echo $url;
           echo "'><img src='$resized_img' width='168' height='168' ";
           echo "'/></a></li>";
           echo "<li><a href='";
           echo $url;
           echo "'/>";
           echo $title;
           echo "</a></li></ul>";
           echo "";
           };
           ?>
       ```
   
 * This gives me all sorts of crazy outputs, text from random posts, images, etc…
   Its supposed to output a list of images and titles for all of the posts in a 
   certain category. Any help would be really appreciated.
 * Oh yeah, I am using a plugin that resizes images on the fly, thats what the the
   wp_get_post_image/getphpthumburl business is.

The topic ‘Featured posts code problem’ is closed to new replies.

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [fangonk](https://wordpress.org/support/users/fangonk/)
 * Last activity: [16 years, 1 month ago](https://wordpress.org/support/topic/featured-posts-code-problem/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
