// Legge tutti i mesi che hanno almeno un post
$query_mese = “SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM ” . $wpdb->posts . ” WHERE post_date <‘” . current_time(‘mysql’) . “‘ AND post_status=’publish’ AND post_type=’post’ AND post_password=” GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC”; $risultati_mese = $wpdb->get_results($query_mese);
if ($risultati_mese) {
// Estrae i risultati per ogni mese
foreach ($risultati_mese as $risultato_mese) {
$questo_mese = zeroise($risultato_mese->month, 2);
$questo_anno = $risultato_mese->year;
// Estrae tutti i post per il mese corrente
$query_post = “SELECT ID, post_date, post_title, comment_count FROM ” . $wpdb->posts . ” WHERE post_date LIKE ‘$questo_anno-$questo_mese-%’ AND post_date AND post_status=’publish’ AND post_type=’post’ AND post_password=” ORDER BY post_date DESC”;
$risultati_post = $wpdb->get_results($query_post);
if ($risultati_post) {
// Mostra il nome del mese e anno
$text = sprintf(‘%s %d’, $month[zeroise($risultato_mese->month,2)], $risultato_mese->year);
$postcount = count($risultati_post);
$output .= ‘
‘ . $text . ‘
‘;
$output .= ”
- \n”;
foreach ($risultati_post as $risultato_post) {
if ($risultato_post->post_date != ‘0000-00-00 00:00:00’) {
$url = get_permalink($risultato_post->ID);
$arc_title = $risultato_post->post_title;
if ($arc_title)
$text = wptexturize(strip_tags($arc_title));
else
$text = $risultato_post->ID;
$title_text = ‘read more “‘ . wp_specialchars($text, 1) . ‘”‘;
$output .= ‘
- ‘ . “$text“;
$output .= “
\n”;
}
}
$output .= ”
\n\n”;
}
}
update_option(‘hfy_archives_’.$ultimo_articolo,$output);
}
else{
$output = ‘‘. __(‘ERROR:’) .’ ‘. __(‘No items were found to be displayed.’) .”;
}
}
echo $output;
?>