syamilmj / Aqua-Resizer

Resize WordPress images on the fly
502 stars 208 forks source link

check my code #6

Closed CyberShot closed 11 years ago

CyberShot commented 11 years ago

I tried your resize script and so far it seems to be working. I am not sure I know what I am doing so I would like for you to check my code please.

I made a widget in the functions.php file. I took code from your example on this page and turned it into a function. Then I called that function in my widget which is displaying in the sidebar. Here is a chunk form my widget

 <?php $loop = new WP_Query( array( 'post_type' => 'gallery', 'posts_per_page' => 6 ) ); ?>
      <ul class="gallery">
      <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <li><?php savior_resize('74', '74', true); ?></li>
      <?php endwhile; wp_reset_query();?>
  </ul>

The loop above queries a custom post type. Then in the functions.php file, I put in this function.

    function savior_resize($height, $width, $crop){
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); 
$image = aq_resize( $img_url, $height, $width, true );

echo '<img src="'.$image.'" />';
   }

What I don't understand is how to get this script to replace the_post_thumbnail? I hate using add_image_size. I added three sizes today and have been working for 4 hours trying to get the right size to show up in the sidebar. I finally added your script and had it working in 5 minutes. So how do I get this script to replace the add_image_size crap so that no matter what image is uploaded through the uploader, the proper size will display. for the sidebar, gallery, post and pages, I pretty much know what size I want but I have to code the the ability for the user to select his own size. Can you offer any advice on how to use this code of yours effectively?

syamilmj commented 11 years ago

Feel free to re-open if you' still need help with the issue above. Closing it now since there hasn't been any reply