Wordpress: creating two thumbnails with different size

Ciao! E’ la prima volta che ti vedo qua, se vuoi seguirmi sottoscrivi il feed RSS.
If you’re new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Se avete bisogno di creare due thumbnail con larghezza differente quando uploadate un’immagine (invece di una sola) potete hackerare il vostro Wordpress in questo modo:

file: /wp-admin/admin-functions.php

funzione: wp_generate_attachment_metadata

Verso la fine della funzione modificatela aggiungendo quello che vedete in neretto:

$max_side = apply_filters( ‘wp_thumbnail_max_side_length’, 240, $attachment_id, $file );
$thumb = wp_create_thumbnail( $file, $max_side );
$max_side2 = apply_filters( ‘wp_thumbnail_max_side_length’, 40, $attachment_id, $thumb );
$thumb2 = wp_create_thumbnail( $thumb, $max_side2 );
$thumb2 = preg_replace( ‘!(\.[^.]+)?$!’, ‘.thumbnail’ . ‘$1′, $thumb2, 1 );

In questo modo ogni volta che farete l’upload di un’immagine (test.jpg per es.) questa creera’  l’immagine test.jpg, test.thumbnail.jpg e infine anche test.thumbnail.thumbnail.jpg
Le due immagini thumbnail avranno come larghezza massima 240px per la prima e 40px per la seconda come dichiarato nella funzione (che potete modificare come volete).

Potete vedere un esempio funzionante sul mio blog di ricette Pizzico di Sale, dove appunto utilizzo questo piccolo hack per creare una piccola icona di ogni ricetta.

Tags: , , , , , , , , , , , ,

Post simili:

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

One Response to “Wordpress: creating two thumbnails with different size”
  1. Rob
    23:05 on November 21st, 2007

    Adoro questi hack per wordpress.. :))
    10x!!!

Leave a comment

(required)

(required)



Comments links could be nofollow free.

Categories