php - How To Use a Different sized Category Image -


hoping can help.

i'm in process of building woocommerce site , i've run problem category images.

when click on shop there page various category thumbnails. when click on thumbnail taken page products relating category.

what i'm looking use same category image previous page header. issue is image @ different size intended i.e full size.

i have stipulated size called feat-img within functions.php can't seem figure out how use it.

here code i'm using display category image:

<?php             if (is_product_category()){                 global $wp_query;                 $cat = $wp_query->get_queried_object();                 $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );                  $image = wp_get_attachment_url( $thumbnail_id );                  echo '<img class="img-responsive" src="'.$image.'" alt="" />';             }         ?> 

any appreciated how use 'feat-img' size.

thanks

first define in functions.php this

add_image_size('300pxsize',300,300); add_image_size( 'full-width-ratio', 600, 9999 ); add_image_size( 'full-width-crop', 600, 300, true ); add_image_size( 'full-width-crop-h200', 600, 200, true );  //get featured image function f_image($id,$width="300pxsize") {     $postthumbnailid = get_post_thumbnail_id( $id );     $imgsrc = wp_get_attachment_image_src( $postthumbnailid, $width);      return  $imgsrc[0]; } // check if post has image function hasfeaturedimage($id) {     $fimg = f_image($id);     if($fimg)     {         return true;     }     return false; } 

then call in page (single.php example) this:

  <?php if(have_posts()) : while(have_posts()) : the_post(); ?>     <?php if(hasfeaturedimage(get_the_id())) : ?>       <div class="single-post-image">         <img src="<?php echo f_image(get_the_id(),"full-width-crop"); ?>" alt="">       </div>     <?php endif; ?>   <?php endwhile;endif;wp_reset_query(); ?> 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -