URL canonical et PluXml
Rédigé par gccyrillus le Aucun commentairee

Le site pluxthemes.com propose de donner à vos thèmes la capacité de générer vos URL canoniques avec quelques lignes de codes à insérer dans le fichier template 'header.php' de votre thème.
Voici les quelques lignes à ajouter pour en bénéficier:
$pagination='';
$reqUri= $plxShow->plxMotor->get;
preg_match('/(/?page[0-9]+)$/', $reqUri, $matches);
if($matches) $pagination =$reqUri;
if($plxShow->catId(true) AND intval($plxShow->catId()) =='0') echo ' <link rel="canonical" href="https://pluxopolis.net/'.$plxShow->plxMotor->urlRewrite().$pagination.'" />'.PHP_EOL ;
if($plxShow->plxMotor->mode=='categorie' $plxShow->catId(true) AND intval($plxShow->catId()) !='0') echo ' <link rel="canonical" href="https://pluxopolis.net/'.$plxShow->plxMotor->urlRewrite('?categorie'. intval($plxShow->catId()).'/'.$plxShow->plxMotor->aCats[$plxShow->catId()]['url']).$pagination.'" />'.PHP_EOL ;
if($plxShow->plxMotor->mode=='article' AND $plxShow->plxMotor->plxRecord_arts->f('numero')) echo ' <link rel="canonical" href="https://pluxopolis.net/'.$plxShow->plxMotor->urlRewrite('?article' . intval($plxShow->plxMotor->plxRecord_arts->f('numero')) . '/' . $plxShow->plxMotor->plxRecord_arts->f('url')).'" />'.PHP_EOL ;
if($plxShow->plxMotor->mode=='static' ) {
echo ' <link rel="canonical" href="https://pluxopolis.net/'.$plxShow->plxMotor->urlRewrite('?static'. intval($plxShow->staticId()).'/'.$plxShow->plxMotor->aStats[str_pad($plxShow->staticId(),3,0,STR_PAD_LEFT)]['url']).'" />'.PHP_EOL ;
}
else{
# enfin on regarde si il s'agit d'un plugin qui squatte les pages statiques
foreach($plxShow->plxMotor->aStats as $k => $val){
if ($val['url'] ==$plxShow->plxMotor->mode) echo ' <link rel="canonical" href="https://pluxopolis.net/'.$plxShow->plxMotor->urlRewrite('?'.$plxShow->plxMotor->mode).'"/>'.PHP_EOL;
}
}
Le script teste si il s'agit de la page d'accueil, puis si c'est une catégorie, un article ou une page statique.avant de servir cette balise "canonical". Il inclus aussi les pages des plugins ainsi que la pagination.
En echo au précédent article, connaitre le mode d'affichage de PluXml est au coeur de ce bout de codes.
DClassé dans : Bout de code ,Mots clés : PHP, Référencement, Scripts, Url Rewrite
A propos de l'auteur, gccyrillus:
Gccyrillus : Amoureux de PluXml et codeur bricoleur à mes heures perdues.