Il problema con le gallerie di immagini associate ai post di WordPress è che queste possono restituire anche l'immagine in evidenza del post. Fortunatamente esiste una soluzione per escludere l'immagine in evidenza. Vediamo quale.
Possiamo usare il seguente codice nel nostro tema:
<?php
$thumb_ID = get_post_thumbnail_id( $post->ID );
if ( $images = get_children(array(
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'post_mime_type' => 'image',
'exclude' => $thumb_ID,
))) : ?>
<ul>
<?php foreach( $images as $image ) : ?>
<li><?php echo wp_get_attachment_link($image->ID, 'thumbnail-latest'); ?></li>
<?php endforeach; ?>
</ul>
<?php else: // Nessuna immagine ?>
<!-- Il post non ha immagini associate -->
<?php endif; ?>
In pratica utilizziamo l'ID dell'immagine in evidenza con il parametro exclude
della funzione get_children
.