Per impostazione predefinita, ogni sito basato su PHP-Fusion visualizza in homepage un estratto di tutte le notizie pubblicate. Questo comportamento, a mio avviso, è già poco accettabile solo se le news sono poche. Anche riducendo il numero delle news processate in news.php (di default sono 11) l’effetto di “invasione” della homepage rimane, a mio avviso.
Ho quindi provveduto a disattivare completamente la visualizzazione automatica delle news e a cercare una soluzione alternativa.
Facendo un po’ di “smanettamento” (l’attività a cui ogni bravo “ingegnere”, secondo i “canoni” che ci vorrebbero inculcare, non dovrebbe dedicarsi) con qualche elemento del codice di PHP-Fusion sono riuscito a scrivere questo blocco di codice per un pannello. Ricopiatelo in un file di testo e caricatelo nella directory infusions/latest_news (o altro nome) della vostra installazione, quindi aggiungete ed attivate il nuovo pannello dall’interfaccia amministrativa, specificando di usare la directory da voi creata come sorgente per il pannello stesso.
< ?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2005 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------*/
/* Infusion by Emanuele Cipolla <info at emanuelecipolla dot net>
/* This infusion shows the latest 5 news, their authors, and their comments (if enabled) in a table. */
if (!defined("IN_FUSION")) { header("Location:../../index.php"); exit; }
opentable("Ultime notizie dalla community");
$query = dbquery("SELECT tn.*, tc.*, tu.user_id,user_name ,COUNT(comment_item_id) AS news_comments
FROM ".$db_prefix."news tn
LEFT JOIN ".$db_prefix."users tu ON tn.news_name=tu.user_id
LEFT JOIN ".$db_prefix."news_cats tc ON tn.news_cat=tc.news_cat_id
LEFT JOIN ".$db_prefix."comments ON news_id=comment_item_id AND comment_type='N'
GROUP BY news_id
ORDER BY news_datestamp DESC LIMIT 0,5");
if (dbrows($query) != 0) {
$i = 0;
echo "<table width='100%' class='tbl-border' cellpadding='0' cellspacing='1'>\n<tr>\n";
echo "<td width='45%' class='tbl2'><span class='small'><b>Categoria</b></span></td>\n";
echo "<td width='55%' class='tbl2'><span class='small'><b>Notizia</b></span></td>\n";
echo "<td class='tbl2' align='center' width='1%' style='white-space:nowrap'><span class='small'><b>Commenti</b></span></td>\n";
echo "<td class='tbl2' align='center' width='1%' style='white-space:nowrap'><span class='small'><b>Inviata da</b></span></td>\n";
echo "<td class='tbl2' align='center' width='1%' style='white-space:nowrap'><span class='small'><b>Pubblicata il</b></span></td>\n";
while($data = dbarray($query)) {
$content = trimlink($data['news_subject'], 50);
$comments = dbcount("(comment_id)", "comments", "comment_type='N' AND comment_item_id='".$data['news_id']."'");
if ($i % 2 == 0) { $row_color = "tbl1"; } else { $row_color = "tbl2"; }
echo "</tr><tr>\n";
echo "<td width='45%' class='$row_color'><span class='small'>".$data['news_cat_name']."</span></td>\n";
echo "<td class='$row_color'><span class='small'>";
echo "<a class='side' href=\"".BASEDIR."news.php?readmore=".$data['news_id']."\">".$content."</a></span>";
echo "</td>\n";
echo "<td class='$row_color' align='center' width='1%' style='white-space:nowrap'><span class='small'>";
if ( $data['news_allow_comments'] == TRUE )
echo "".$data['news_comments']."";
else
echo "–";
echo "</span></td>\n";
echo "<td class='$row_color' align='center' width='1%' style='white-space:nowrap'><p align='center'>";
echo "<span class='small'><a href='profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a></span>";
echo "</p></td>\n";
echo "<td class='$row_color' align='center' width='1%' style='white-space:nowrap'><span class='small'>";
echo showdate("shortdate", $data['news_datestamp']);
echo "</span></td>\n</tr>\n";
$i++;
}
} else {
echo "<center>".$locale['004']."</center>\n";
}
echo "</table>";
closetable();
?>
Il risultato che dovreste ottenere, se avete svolto i passaggi correttamente, sarà simile a quanto si vede in questo screenshot (preso su Massimo 30:
Credo che così vada molto meglio
Enjoy.



Commenti recenti