PluXML : faire un plan de site

La page du wiki officiel ayant été effacée, et parce que c'est tout de même une fonction bien pratique à insérer sur un site, voici comment faire un plan de site sous PluXML 5+.

Il suffit de créer une nouvelle page statique et d'y insérer le contenu ci-dessous :

lang-php
<?php
# Page statique Pluxml : liste de tous les articles par catégories par stephane@pluxml.org
# révision 2.0 par Yomli :
#	- compatibilité pluxml 5+ 

global $plxShow;
#=======PARAMÈTRES ========
# format de la date
$format_date = '#num_day/#num_month/#num_year(4)';
 
# liste des catégories à afficher
# exemple: $catList = ''; = articles de toutes les catégories, 
# exemple: $catList = '001|003'; = articles des catégories 001 et 003 uniquement
$catList = ''; 
# nombre d'articles à afficher par catégorie, mettre 0 pour lister tous les articles
$artsByCategory = 0; 
#==========================
?>

<h4>Pages statiques</h4>
<ul class="alt">
	<?php $plxShow->staticList('Accueil','<li id="#static_id"><a href="#static_url" class="#static_status" title="#static_name">#static_name</a></li>'); ?>
</ul>

<h4>Catégories</h4>
<ul class="alt">
	<?php $plxShow->catList('','<li id="#cat_id" class="#cat_status"><a href="#cat_url" title="#cat_name">#cat_name</a></li>'); ?>
</ul>

<h4>Articles</h4>
<?php
$plx_arts = array();
$plxGlob_arts = plxGlob::getInstance(PLX_ROOT.$plxShow->plxMotor->aConf['racine_articles']);
$aFiles = $plxGlob_arts->query('/[0-9]{4}.[home|0-9,]*'.$catList.'[0-9,]*.[0-9]{3}.[0-9]{12}.[a-z0-9-]+.xml$/','art','rsort',0,false,'before');
$aCatList = explode('|', $catList);
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);
		$cats = explode(',', $temp['categorie']);
		foreach($cats as $cat) {
			if($catList=='' OR in_array($cat, $aCatList)) {
				if(!isset($plx_arts[$cat]))
					$plx_arts[$cat][] = $temp;
				elseif(intval(sizeof($plx_arts[$cat])) < $artsByCategory OR $artsByCategory == 0)
					$plx_arts[$cat][] = $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) {

			$cat_num = $k;
		
			# on trie en fonction de l'ordre d'affichage des articles dans la catégorie
			if($cat_num=='home') {
				if ($plxShow->plxMotor->aConf['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"]);'));
				echo '<h5><a href="'.$plxShow->plxMotor->aConf['racine'].'">Accueil</a></h5>';
			}
			elseif(!isset($plxShow->plxMotor->aCats[$cat_num])) {
				if ($plxShow->plxMotor->aConf['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"]);'));
				echo '<h5>Non classé</h5>';
			} 
			else {
				if ($plxShow->plxMotor->aCats[$cat_num]['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_name = plxUtils::strCheck($plxShow->plxMotor->aCats[ $cat_num ]['name']);
				$cat_url = $plxShow->plxMotor->aCats[ $cat_num ]['url'];
				echo '';				
			}
			echo "<h5>".$cat_name."</h5><ul class='alt'>";
			# 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::formatDate($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>";
        }

    }
}
?>

----

Permaliens :