Risposte nei forum create
-
AutorePost
-
milesfaberPartecipante
Ho scritto e usato questo codice per visualizzare una navigazione per mese solo se viene richiesto un mese dall’archivio:
<?php
// se richiedo un mese dell’archivio
if (is_month()) {
// recupero il mese richiesto che è nella forma: aaaamm e divido l’anno dal mese
$datarichiesta = $_GET;
$meserichiesto = substr($datarichiesta,4,2);
$annorichiesto = substr($datarichiesta,0,4);
// recupero il mese e l’anno correnti
$mesecorrente = date(‘m’, strtotime($date));
$annocorrente = date(‘Y’, strtotime($date));
// imposto il mese e l’anno in cui inizia il blog
$annoinizio = 2003;
$meseinizio = 1;
// imposto le query per i link al mese precedente e successivo
if ($meserichiesto != 1) {
$mesemeno = $meserichiesto-1;
if ($mesemeno<10) $mesemeno = “0”.$mesemeno;
$annomeno = $annorichiesto;
$querymeno = $annomeno.$mesemeno;
} else {
$mesemeno = 12;
$annomeno = $annorichiesto-1;
$querymeno= $annomeno.$mesemeno;
}
if ($meserichiesto != 12) {
$mesepiu = $meserichiesto+1;
if ($mesepiu<10) $mesepiu = “0”.$mesepiu;
$annopiu = $annorichiesto;
$querypiu= $annopiu.$mesepiu;
} else {
$mesepiu = “01”;
$annopiu = $annorichiesto+1;
$querypiu= $annopiu.$mesepiu;
}
//se esiste precedente mostro link
if ($annorichiesto>$annoinizio) {
echo “<a href='”;
bloginfo(‘url’);
echo “?m=”.$querymeno.”‘>« Mese precedente | “;
} elseif ($annorichiesto==$annoinizio && $meserichiesto>$meseinizio) {
echo “<a href='”;
bloginfo(‘url’);
echo “?m=”.$querymeno.”‘>« Mese precedente | “;
}
//mostro mese attualmente visualizzato
$meseanno = single_month_title(‘ ‘,false);
echo ” “.$meseanno.” “;
//se esiste successivo mostro link
if ($annorichiesto<$annocorrente) {
echo ” | <a href='”;
bloginfo(‘url’);
echo “?m=”.$querypiu.”‘>Mese successivo »”;
} elseif ($annorichiesto==$annocorrente && $meserichiesto<$mesecorrente) {
echo ” | <a href='”;
bloginfo(‘url’);
echo “?m=”.$querypiu.”‘>Mese successivo »”;
}
}
?>
-
AutorePost