WordPress: risolvere il problema delle date dei post pubblicati nello stesso giorno

Se la funzione the_date() viene usata su più post con la stessa data, il suo output apparirà solo sul primo post.

WordPress di Gabriele Romanato

Vi sarà sicuramente capitato di utilizzare la funzione di WordPress the_date() e di imbattervi in un problema curioso: se la funzione viene usata su più post con la stessa data, il suo output apparirà solo sul primo post.

La documentazione di WordPress ci offre la soluzione:

SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string. Use <?php the_time( get_option( 'date_format' ) ); ?> to add the date set in the admin interface.

In pratica per le categorie, i tag, il Loop della home page, gli archivi o più in generale per quelle sezioni che mostrano una serie di post dovremmo usare la funzione the_time().

Commenti