Creación de tamaños de imagen personalizados por tipo de post

  • Autor Autor Darwin Fernandez
  • Fecha de inicio Fecha de inicio
D

Darwin Fernandez

Hola amigos de forobeta ando editando mi theme y optimizandolo y ahora quisiera crear tamaños de imagen personalizados para cada tipo de post por ejemplo si es Tipo de Post películas al subir una imagen se cree 3 tamaños de imagen diferentes si es Tipo de Post Series se cree otros 3 tamaños de imagen diferentes y bueno ya en cada sección llamar a ese tamaño de imagen para que en vez de la imagen normal se cargue la imagen exacta para ese apartado y de esa manera cargue un poco mas rápido pero he estado buscando informacion de como hacerlo para cada Postype y no encuentro alguien me podria dar una manito :sorrow::sorrow:

PD : En el titulo era Crear se me cruzaron las teclas y escribí "Cree" :'(
 
Insertar CODE, HTML o PHP:
add_filter( 'intermediate_image_sizes_advanced', 'set_thumbnail_size_by_post_type', 10);

function set_thumbnail_size_by_post_type( $sizes ) {

 $type = get_post_type($_REQUEST['post_id']);

    switch ($type) :
        case 'resumenes' :
            $sizes['thumbnail'] = array( 
                         'width' => '218', 'height' => '340', 'crop' => true);
            break;
			
        default :
            $sizes['thumbnail'] = array( 
                         'width' => get_option('thumbnail_size_w'), 'height' => get_option('thumbnail_size_h'), 'crop' => true);
            break;

    endswitch;
	
    switch ($type) :
        case 'resumenes' :	   
		    $sizes['medium'] = array( 
                         'width' => '154', 'height' => '233', 'crop' => true);
            break;
			

		default:
			$sizes['medium'] = array( 
                         'width' => get_option('medium_size_w'), 'height' => get_option('medium_size_h'), 'crop' => false);
            break;
    endswitch;
	
    switch ($type) :
		case 'resumenes':
            $sizes['large'] = array( 
                         'width' => '102', 'height' => '149', 'crop' => true);
            break;

		default:
            $sizes['large'] = array( 
                         'width' => get_option('large_size_w'), 'height' => get_option('large_size_h'), 'crop' => false);
            break;
    endswitch;

    return $sizes;

}

solo tienes que cambiar el post type y el width y height de cada tamaño. :encouragement:
 
Insertar CODE, HTML o PHP:
add_filter( 'intermediate_image_sizes_advanced', 'set_thumbnail_size_by_post_type', 10);

function set_thumbnail_size_by_post_type( $sizes ) {

 $type = get_post_type($_REQUEST['post_id']);

    switch ($type) :
        case 'resumenes' :
            $sizes['thumbnail'] = array( 
                         'width' => '218', 'height' => '340', 'crop' => true);
            break;
            
        default :
            $sizes['thumbnail'] = array( 
                         'width' => get_option('thumbnail_size_w'), 'height' => get_option('thumbnail_size_h'), 'crop' => true);
            break;

    endswitch;
    
    switch ($type) :
        case 'resumenes' :       
            $sizes['medium'] = array( 
                         'width' => '154', 'height' => '233', 'crop' => true);
            break;
            

        default:
            $sizes['medium'] = array( 
                         'width' => get_option('medium_size_w'), 'height' => get_option('medium_size_h'), 'crop' => false);
            break;
    endswitch;
    
    switch ($type) :
        case 'resumenes':
            $sizes['large'] = array( 
                         'width' => '102', 'height' => '149', 'crop' => true);
            break;

        default:
            $sizes['large'] = array( 
                         'width' => get_option('large_size_w'), 'height' => get_option('large_size_h'), 'crop' => false);
            break;
    endswitch;

    return $sizes;

}

solo tienes que cambiar el post type y el width y height de cada tamaño. :encouragement:


Muchas gracias amigo 🙂 me vino de 10 el código ya lo probé cambie los tipo de post y me funciono tengo una preguntilla como haría para que no corte la imagen por que la corta un poco, como haría para que la reduzca sin cortalo, nuevamente gracias :welcoming:
 
crop en false :encouragement:
 
Atrás
Arriba