Miriam, un membro di questo fantastico staff, ci ha fatto il favore di scrivere questa sezione perché conosce perfettamente l'argomento.
Recupera la miniatura del post.
Descrizione
Quando un tema aggiunge il supporto per le "post-thumbnail", viene registrata una speciale dimensione dell'immagine "post-thumbnail", che differisce dalla dimensione dell'immagine "thumbnail" gestita tramite la schermata Impostazioni > Media.
Quando si usa the_post_thumbnail() o le funzioni correlate, la dimensione dell'immagine "post-thumbnail" viene utilizzata per impostazione predefinita, anche se è possibile specificare una dimensione diversa, se necessario.
Parametri
- $post
-
(int|WP_Post)(Opzionale) ID del post o oggetto WP_Post. L'impostazione predefinita è globale
$post
.Valore predefinito: null
- $dimensione
-
(stringa|int[])(Opzionale) Dimensione immagine. Accetta qualsiasi nome di dimensione dell'immagine registrata o un array di valori di larghezza e altezza in pixel (in quest'ordine).
Valore predefinito: 'post-thumbnail'.
- $attr
-
(stringa|array)(Opzionale) Stringa di query o array di attributi.
Valore predefinito: ''
Ritorno
(stringa) Il tag dell'immagine miniaturizzata del post.
Altre informazioni
Se l'elemento richiesto add_theme_support( 'post-thumbnails' );
nel file functions.php del tema corrente è collegato a un hook, deve essere chiamato prima del file init
sia lanciato. Il init può essere troppo tardi per alcune funzioni. Se collegato a un gancio, deve essere after_setup_theme
.
Fonte
File: wp-includes/post-thumbnail-template.php
functionget_the_post_thumbnail($post=null,$size='post-thumbnail',$attr=''){$post=get_post($post);if(!$post){return'';}$post_thumbnail_id=get_post_thumbnail_id($post);/** * Filters the post thumbnail size. * * @since 2.9.0 * @since 4.9.0 Added the `$post_id` parameter. * * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param int $post_id The post ID. */$size=apply_filters('post_thumbnail_size',$size,$post->ID);if($post_thumbnail_id){/** * Fires before fetching the post thumbnail HTML. * * Provides "just in time" filtering of all filters in wp_get_attachment_image(). * * @since 2.9.0 * * @param int $post_id The post ID. * @param int $post_thumbnail_id The post thumbnail ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */do_action('begin_fetch_post_thumbnail_html',$post->ID,$post_thumbnail_id,$size);if(in_the_loop()){update_post_thumbnail_cache();}$html=wp_get_attachment_image($post_thumbnail_id,$size,false,$attr);/** * Fires after fetching the post thumbnail HTML. * * @since 2.9.0 * * @param int $post_id The post ID. * @param int $post_thumbnail_id The post thumbnail ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). */do_action('end_fetch_post_thumbnail_html',$post->ID,$post_thumbnail_id,$size);}else{$html='';}/** * Filters the post thumbnail HTML. * * @since 2.9.0 * * @param string $html The post thumbnail HTML. * @param int $post_id The post ID. * @param int $post_thumbnail_id The post thumbnail ID. * @param string|int[] $size Requested image size. Can be any registered image size name, or * an array of width and height values in pixels (in that order). * @param string $attr Query string of attributes. */returnapply_filters('post_thumbnail_html',$html,$post->ID,$post_thumbnail_id,$size,$attr);}
Correlato
Utilizzi
Usi | Descrizione |
---|---|
wp-includes/query.php: in_the_loop() |
Determina se il chiamante è nel loop. |
wp-includes/plugin.php: applica_filtri() |
Richiama le funzioni di callback che sono state aggiunte a un gancio per filtri. |
wp-includes/plugin.php: do_action() |
Esegue le funzioni agganciate a un gancio di azione specifico. |
wp-includes/post-thumbnail-template.php: get_post_thumbnail_id() |
Recupera l'ID della miniatura del post. |
wp-includes/post-thumbnail-template.php: update_post_thumbnail_cache() |
Aggiorna la cache per le miniature nel ciclo corrente. |
wp-includes/post-thumbnail-template.php: post_thumbnail_size |
Filtra la dimensione della miniatura del post. |
wp-includes/post-thumbnail-template.php: begin_fetch_post_thumbnail_html |
Si attiva prima di recuperare l'HTML della miniatura del post. |
wp-includes/post-thumbnail-template.php: end_fetch_post_thumbnail_html |
Si attiva dopo aver recuperato l'HTML della miniatura del post. |
wp-includes/post-thumbnail-template.php: post_thumbnail_html |
Filtra l'HTML della miniatura del post. |
wp-includes/media.php: wp_get_attachment_image() |
Ottiene un elemento HTML img che rappresenta un'immagine allegata. |
wp-includes/post.php: get_post() |
Recupera i dati di un post, dato un ID o un oggetto post. |
Utilizzato da
Usato da | Descrizione |
---|---|
wp-includes/post-thumbnail-template.php: the_post_thumbnail() |
Visualizza la miniatura del post. |
Changelog
Versione | Descrizione |
---|---|
4.4.0 | $post può essere un ID di post o un oggetto WP_Post. |
2.9.0 | Introdotto. |