Pour lister tous les articles de pluxml par catégorie dans une page statique
- créer une page statique
- copier le code ci-dessous dans la page statique
- sauvegarder
Pour Pluxml 4.3+
Code :
<?php
# Page statique Pluxml : liste de tous les articles par catégories par stephane@pluxml.org
# revision 1.0 par Stephane:
# - compatibilité pluxml 4.3
# - paramètrage du format de la date
# - tri des categorie en fonction de l'ordre d'affichage des catégories
# - tri des articles par catégories en fonction de l'ordre d'affichage des articles dans la catégorie
# revision 1.1 par Stephane (06/04/2010) :
# - ne pas prendre en compte les articles futurs
if(!defined('PLX_ROOT')) exit;
# Renseignez ici le format de la date
$format_date = '#num_day/#num_month/#num_year(4)';
global $plxShow;
$plxGlob_arts = new plxGlob(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
$aFiles = $plxGlob_arts->query('/[0-9]{4}.(CAT_ID).[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
if(is_array($aFiles)) { # On a des fichiers
while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
$temp = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);
$plx_arts[$temp['categorie']][] = $temp;
}
if($plx_arts) { # On a des articles
# tri en fonction de l'ordre d'affiche des catégories
uksort($plx_arts, create_function('$a, $b', 'global $plxShow; return strcmp(array_search($a, array_keys($plxShow->plxMotor->aCats)), array_search($b, array_keys($plxShow->plxMotor->aCats)));'));
# On boucle sur nos articles
foreach ($plx_arts as $k => $v) {
# on trie en fonction de l'ordre d'affichage des articles dans la catégorie
if ($plxShow->plxMotor->aCats[$k]['tri'] == 'asc') usort($v, create_function('$a, $b', 'return strcmp($a["date"], $b["date"]);'));
else usort($v, create_function('$a, $b', 'return strcmp($b["date"], $a["date"]);'));
$cat_num = $k;
$cat_name = plxUtils::strCheck($plxShow->plxMotor->aCats[ $cat_num ]['name']);
$cat_url = $plxShow->plxMotor->aCats[ $cat_num ]['url'];
echo '<h2><a href="'.$plxShow->plxMotor->aConf['racine'].'?categorie'.$cat_num.'/'.$cat_url.'">'.$cat_name.'</a></h2>';
echo "<ul>";
# On boucle sur les articles de la categories
while(list($null, $art) = each($v)) {
$art_num = intval($art['numero']);
$art_url = plxUtils::strCheck(($art['url']));
$art_title = plxUtils::strCheck(($art['title']));
$art_date = plxDate::dateIsoToHum($art['date'], $format_date);
echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>';
}
echo "</ul>";
}
}
}
?>
CAT_ID correspond à l'id de la catégorie souhaitée
On peux spécifier plusieurs catégories de cette façon
CAT_ID1|CAT_ID2
Exemple:
Code : $aFiles = $plxGlob_arts->query('/[0-9]{4}.(001|002).[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
Pour prendre en compte toutes les catégories, remplacer CAT_ID par Code : [0-9]{3}
Exemple:
Code : $aFiles = $plxGlob_arts->query('/[0-9]{4}.([0-9]{3}).[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
Pour Pluxml 4.2+
Code :
<?php
# Page statique Pluxml : liste de tous les articles par catégories par stephane@pluxml.org
# revision 1.0 par Stephane:
# - compatibilité pluxml 4.2
# - paramètrage du format de la date
# - tri des categorie en fonction de l'ordre d'affichage des catégories
# - tri des articles par catégories en fonction de l'ordre d'affichage des articles dans la catégorie
# revision 1.1 par Stephane (06/04/2010) :
# - ne pas prendre en compte les articles futurs
if(!defined('PLX_ROOT')) exit;
# Renseignez ici le format de la date
$format_date = '#num_day/#num_month/#num_year(4)';
global $plxShow;
$plxGlob_arts = new plxGlob(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
$aFiles = $plxGlob_arts->query('/[0-9]{4}.([0-9]{3}).[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
if(is_array($aFiles)) { # On a des fichiers
while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
$temp = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);
$plx_arts[$temp['categorie']][] = $temp;
}
if($plx_arts) { # On a des articles
# tri en fonction de l'ordre d'affiche des catégories
uksort($plx_arts, create_function('$a, $b', 'global $plxShow; return strcmp(array_search($a, array_keys($plxShow->plxMotor->aCats)), array_search($b, array_keys($plxShow->plxMotor->aCats)));'));
# On boucle sur nos articles
foreach ($plx_arts as $k => $v) {
# on trie en fonction de l'ordre d'affichage des articles dans la catégorie
if ($plxShow->plxMotor->aCats[$k]['tri'] == 'asc') usort($v, create_function('$a, $b', 'return strcmp($a["date"], $b["date"]);'));
else usort($v, create_function('$a, $b', 'return strcmp($b["date"], $a["date"]);'));
$cat_num = $k;
$cat_name = plxUtils::strCheck($plxShow->plxMotor->aCats[ $cat_num ]['name']);
$cat_url = $plxShow->plxMotor->aCats[ $cat_num ]['url'];
echo '<h2><a href="'.$plxShow->plxMotor->aConf['racine'].'?categorie'.$cat_num.'/'.$cat_url.'">'.$cat_name.'</a></h2>';
echo "<ul>";
# On boucle sur les articles de la categories
while(list($null, $art) = each($v)) {
$art_num = intval($art['numero']);
$art_url = plxUtils::strCheck(($art['url']));
$art_title = plxUtils::strCheck(($art['title']));
$art_date = plxDate::dateIsoToHum($art['date'], $format_date);
echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>';
}
echo "</ul>";
}
}
}
?>
Pour Pluxml 4.1.x
Code :
<?php
if(!defined('PLX_ROOT')) exit;
global $plxShow;
$plxGlob_arts = & new plxGlob(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
$aFiles = $plxGlob_arts->query('/[0-9]{4}.([0-9]{3}).[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
# On parse les fichiers
if(is_array($aFiles)) { # On a des fichiers
while(list($k,$v) = each($aFiles)) { # On parcourt tous les fichiers
$temp = $plxShow->plxMotor->parseArticle(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles'].$v);
$plx_arts[$temp['categorie']][] = $temp;
}
if($plx_arts) { # On a des articles
ksort($plx_arts);
# On boucle sur nos articles
foreach ($plx_arts as $k => $v) {
usort($v, create_function('$a, $b', 'return strcmp($b["date"], $a["date"]);'));
$cat_num = $k;
$cat_name = htmlspecialchars($plxShow->plxMotor->aCats[ $cat_num ]['name'],ENT_QUOTES,PLX_CHARSET);
$cat_url = $plxShow->plxMotor->aCats[ $cat_num ]['url'];
echo '<h2><a href="'.$plxShow->plxMotor->aConf['racine'].'?categorie'.$cat_num.'/'.$cat_url.'">'.$cat_name.'</a></h2>';
echo "<ul>";
# On boucle sur les articles de la categories
while(list($null, $art) = each($v)) {
$art_num = intval($art['numero']);
$art_url = htmlspecialchars($art['url'],ENT_QUOTES,PLX_CHARSET);
$art_title = htmlspecialchars($art['title'],ENT_QUOTES,PLX_CHARSET);
$art_date = substr($art['date'], 8, 2).'/'.substr($art['date'], 5, 2).'/'.substr($art['date'], 0, 4);
echo '<li>'.$art_date.': <a href="'.$plxShow->plxMotor->aConf['racine'].'?article'.$art_num.'/'.$art_url.'">'.$art_title.'</a></li>';
}
echo "</ul>";
}
}
}
?>
|