Récupérer les données du configuration.xml pour le schema json

garys02garys02 Member
9 nov. modifié dans Discussions générales

Bonjour,

Quelqu'un pourrait me donner la réponse pour récupérer les données de la configuration et les mettre là dedans, notamment le titre du site et la description pour mon header car voici ce que j'ai mis et ça ne marche pas :

<script type="application/ld+json">
{
      "@context": "http://schema.org",
      "@type": "Business",
      "name": "<?php echo htmlspecialchars($parametreTitle); ?>", 
      "image": "<?php echo $plxShow->template(); ?>/img/bg.webp",
      "url": "<?php echo $plxShow->rootUrl(); ?>",
      "category": "Business",
      "description": "<?php echo $plxConfig->get('meta_description'); ?>"
}
</script>

Merci

Réponses

  • garys02garys02 Member
    9 nov. modifié

    Bon voilà la réponse mais j'ai un problème maintenant avec les caractères spéciaux comme les apostrophes qui affichent &#039; dans la meta description du script et du site également.

    Correctif :

     <script type="application/ld+json">
        {
            "@context": "http://schema.org", 
            "@type": "Business", 
            "name": "<?php echo plxUtils::strCheck($plxShow->plxMotor->aConf['title']); ?>", 
            "description": "<?php echo plxUtils::strCheck($plxShow->plxMotor->aConf['meta_description']); ?>", 
            "url": "<?php echo $plxShow->plxMotor->racine; ?>", 
            "image": "<?php echo $plxShow->plxMotor->racine; ?>themes/defaut/img/bg.webp" 
        }
        </script>
    
  • bazooka07bazooka07 PluXml Lead Developer, Moderator
    11 nov. modifié

    Bonjour,

    Ta méthode renvoie toujours la même information quelque soit l'article, la catégorie, le mot-clé ou la page statique. C'est plu compliqué que cela :

        <script type="application/ld+json">
    <?php
    ob_start();
    ?>
    <?= $plxShow->template(); ?>/img/bg.webp
    <?php
    # image par défaut
    $image = trim(ob_get_clean());
    
    switch($plxShow->mode()) {
        case 'article' :
            $url = $plxShow->artUrl(false);
            $thumbnail = $plxShow->artThumbnail('#img_url', false);
            if(!empty($thumbnail)) {
                $image = $thumbnail;
            }
            break;
        case 'categorie' :
            $url = $plxShow->catUrl($plxShow->plxMotor->cible);
            $thumbnail = $plxShow->catThumbnail('#img_url', false);
            if(!empty($thumbnail)) {
                $image = $thumbnail;
            }
            break;
        case 'tags' : $url = $plxShow->plxMotor->urlRewrite('?tag/' . plxUtils::urlify($plxShow->plxMotor->cible)); break;
        case 'static' : $url = $plxShow->staticUrl(false); break;
        default : $url = $plxShow->plxMotor->racine;
    }
    ?>
    {
          "@context": "http://schema.org",
          "@type": "Business",
          "name": "<?php $plxShow->pageTitle($plxShow->mode() . '=#title'); ?>",
          "image": "<?= $image ?>",
          "url": "<?= $url ?>",
    <?php
    ob_start();
    $plxShow->meta('description');
    $description = trim(ob_get_clean());
    if(!empty($description)) {
        $description = preg_replace('#^<meta.*\bcontent\s*="([^"]*)".*>$#', '$1', $description);
    ?>
          "description": "<?= $description ?>",
    <?php
    }
    ?>
          "category": "Business"}
        </script>
    
  • garys02garys02 Member
    9 nov. modifié

    J'ai réussi avec ça :

    <script type="application/ld+json">
        {
            "@context": "http://schema.org",
            "@type": "Business",
            "name": "<?php echo html_entity_decode($plxShow->plxMotor->aConf['title'], ENT_NOQUOTES, 'UTF-8'); ?>",
            "description": "<?php echo html_entity_decode($plxShow->plxMotor->aConf['meta_description'], ENT_NOQUOTES, 'UTF-8'); ?>",
            "url": "<?php echo $plxShow->plxMotor->racine; ?>",
            "image": "<?php echo $plxShow->plxMotor->racine; ?>themes/defaut/img/pluxml-logo-black.png"
        }
    </script>
    

    Pour le Json qui présente l'entreprise je laisse les données générales sur toutes les pages, par contre ça va peut etre me serir pour les balises opengraph, merci je vais voir ça.

  • garys02garys02 Member
    9 nov. modifié

    Comment obtenir la meta description seule sans que ça démarre par : <meta name="description" content=" ?
    <meta property="og:description" content="<?php $plxShow->meta('description'); ?>"
    ça me donne :
    <meta property="og:description" content=" <meta name="description" content="Mon blog est ouvert , bonjour à tous..." />"

  • bazooka07bazooka07 PluXml Lead Developer, Moderator

    Il faut capturer la sortie du buffer de PHP (ob_start();) et la modifier avec preg_replace().
    Voir mon billet précèdent
    J'ai permuté les propriétés category et description pour gérer la dernière virgule.

  • garys02garys02 Member
    10 nov. modifié

    Merci

Connectez-vous ou Inscrivez-vous pour répondre.