News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

[TuTo]Microdata - Breadcrumbs - SMF

Started by Dhayzon, July 19, 2016, 03:46:41 PM

Previous topic - Next topic

Dhayzon

dentro de la funcion
function theme_linktree($force_show = false)


esta  nuestro  Breadcrumb De SMF, exactamente  en el archivo Index.template.php de nuestro tema.

no te tengo que explicar que es esto o para que sirve, Esta información es redundante y existen muchos artículos en Internet que te explican detalladamente que significa microdata y cual es su función.
pero te dejo el link para que te informes, Esto para que sepas que estamos haciendo
https://developers.google.com/search/docs/data-types/breadcrumbs

Buscaremos  y reemplazaremos esto

// Show a linktree. This is that thing that shows "My Community | General Category | General Discussion"..
function theme_linktree($force_show = false)
{
global $context, $settings, $options, $shown_linktree;

// If linktree is empty, just return - also allow an override.
if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
return;

echo '
<div class="navigate_section">
<ul>';

// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

// Show something before the link?
if (isset($tree['extra_before']))
echo $tree['extra_before'];

// Show the link, including a URL if it should have one.
echo $settings['linktree_link'] && isset($tree['url']) ? '
<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>' : '<span>' . $tree['name'] . '</span>';

// Show something after the link...?
if (isset($tree['extra_after']))
echo $tree['extra_after'];

// Don't show a separator for the last one.
if ($link_num != count($context['linktree']) - 1)
echo ' &#187;';

echo '
</li>';
}
echo '
</ul>
</div>';

$shown_linktree = true;
}


por este otro

function theme_linktree($force_show = false)
{
global $context, $settings, $options, $shown_linktree;

// If linktree is empty, just return - also allow an override.
if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
return;

echo '
<div class="navigate_section">
<ol itemscope itemtype="http://schema.org/BreadcrumbList">';
    $pItemprop = 1;
// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '  itemprop="itemListElement" itemscope
itemtype="http://schema.org/ListItem">';

// Show something before the link?
if (isset($tree['extra_before']))
echo $tree['extra_before'];

// Show the link, including a URL if it should have one.
echo $settings['linktree_link'] && isset($tree['url']) ? '
<a itemprop="item" href="' . $tree['url'] . '"><span  itemprop="name">' . $tree['name'] . '</span></a>' : '<span  itemprop="name">' . $tree['name'] . '</span>';

// Show something after the link...?
if (isset($tree['extra_after']))
echo $tree['extra_after'];

// Don't show a separator for the last one.
if ($link_num != count($context['linktree']) - 1)
echo ' <span> &#187;</span>';

echo '<meta itemprop="position" content="'.$pItemprop++.'" />
</li>';
}
echo '
</ol>
</div>';

$shown_linktree = true;
}


el resultado y  para que lo hacemos, ya puedes leerlo y analizarlo detenidamente en el link que te deje arriba.

esta validado en https://search.google.com/structured-data/testing-tool

-Rock Lee-

Parece interesante algo había leído pero no había tenido tiempo :P de entenderlo del todo... ya lo mirare y probare en un smf de pruebas tengo!


Saludos!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

^SoporteGSM^

Basicamente para que sirve este microdata???

vicram10


jclconsultor

Buenas tardes Dhayzon, gracias por tu idea, la tome y la efectúe de otra versión como schema, para evitar un efecto que me causa en mi tema bellacita del Forotailandia, anexo como la realice, saludos.

NOTA: A igual que la versión realizada por ti, solo tienes que copiar la función y listo, pruebas con la herramienta de google y indexa, saludos.


function theme_linktree($force_show = false) {
   global $context, $settings, $options, $shown_linktree;
   $Ae_index = 0;
   $i=0;$listitem=null;
   
   if(!empty($_REQUEST['action']) || !empty($_REQUEST['topic']) || !empty($_REQUEST['board']) || !empty($_REQUEST['page']) || !empty($_REQUEST['blog']))
      $Ae_index = 1;

   if(empty($Ae_index))
      return;

   // If linktree is empty, just return - also allow an override.
   if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
      return;

   echo '
   <div class="navigate_section">
      <ul>';

   // Each tree item has a URL and name. Some may have extra_before and extra_after.
   foreach ($context['linktree'] as $link_num => $tree) {
      $i++;
      echo '
         <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

      // Show something before the link?
      if (isset($tree['extra_before']))
         echo $tree['extra_before'];
      
      // Show the link, including a URL if it should have one.
      echo $settings['linktree_link'] && isset($tree['url']) ? '
            <a href="'.$tree['url'].'"><span>'.$tree['name'].'</span></a>' : '<span>'.$tree['name'].'</span>';
                  
      // Show something after the link...?
      if (isset($tree['extra_after']))
         echo $tree['extra_after'];

      // Don't show a separator for the last one.
      if ($link_num != count($context['linktree']) - 1)
         echo ' &#187;';
      
      echo '
         </li>';
      
      //JCL SCHEMA BreadcrumbList index.template - fun theme_linktree
      if ($listitem!=null){$listitem .=',';}
      $listitem .= '
         {"@type": "ListItem",
         "position": '.$i.',
         "item": {
           "@id": "'.$tree['url'].'",
           "name": "'.$tree['name'].'"}
         }';
      //--
   }
   echo '
      </ul>
   </div>';
   
   //BreadcrumbList
   echo '
   
      <!-- JCL SCHEMA BreadcrumbList index.template - fun theme_linktree -->
      
      <script type="application/ld+json">
      {
        "@context": "schema.org",
        "@type": "BreadcrumbList",
        "itemListElement":
        ['.$listitem.']
      }
      </script>
      
      <!-- /JCL SCHEMA BreadcrumbList index.template - fun theme_linktree -->
      
   ';
   //--
   $shown_linktree = true;
}

jclconsultor

Disculpen todos, pero seguí validando ya que en mi tema bellacita se repite 2 veces el esquema y agregue unos cambios con variables globales que impide que se repita el schema en el tema, quedando perfecto:

Nota: por razones de limitacion por politicas de span en el foro, en donde indica la url: hxxp:schema.org [nonactive] hay que colocar h t t p: / / hxxp:schema.org [nonactive], en forma correcta.

function theme_linktree($force_show = false) {
   global $context, $settings, $options, $shown_linktree;
   $Ae_index = 0;
   
   //JCL SCHEMA BreadcrumbList index.template - fun theme_linktree
   global $jcl_schema;
   global $jcl_schemaold;
   $i=0;$listitem=null;
   //--
   
   if(!empty($_REQUEST['action']) || !empty($_REQUEST['topic']) || !empty($_REQUEST['board']) || !empty($_REQUEST['page']) || !empty($_REQUEST['blog']))
      $Ae_index = 1;

   if(empty($Ae_index))
      return;

   // If linktree is empty, just return - also allow an override.
   if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
      return;

   echo '
   <div class="navigate_section">
      <ul>';

   // Each tree item has a URL and name. Some may have extra_before and extra_after.
   foreach ($context['linktree'] as $link_num => $tree) {
      $i++;
      echo '
         <li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

      // Show something before the link?
      if (isset($tree['extra_before']))
         echo $tree['extra_before'];
      
      // Show the link, including a URL if it should have one.
      echo $settings['linktree_link'] && isset($tree['url']) ? '
            <a href="'.$tree['url'].'"><span>'.$tree['name'].'</span></a>' : '<span>'.$tree['name'].'</span>';
                  
      // Show something after the link...?
      if (isset($tree['extra_after']))
         echo $tree['extra_after'];

      // Don't show a separator for the last one.
      if ($link_num != count($context['linktree']) - 1)
         echo ' &#187;';
      
      echo '
         </li>';
      
      //JCL SCHEMA BreadcrumbList index.template - fun theme_linktree
      if ($listitem!=null){$listitem .=',';}
      $listitem .= '
         {"@type": "ListItem",
         "position": '.$i.',
         "item": {
           "@id": "'.$tree['url'].'",
           "name": "'.$tree['name'].'"}
         }';
      //--
   }
   echo '
      </ul>
   </div>';
   
   //BreadcrumbList
   $jcl_schema = '
   
      <!-- JCL SCHEMA BreadcrumbList index.template - fun theme_linktree -->
      
      <script type="application/ld+json">
      {
        "@context": "hxxp:schema.org [nonactive]",
        "@type": "BreadcrumbList",
        "itemListElement":
        ['.$listitem.']
      }
      </script>
      
      <!-- /JCL SCHEMA BreadcrumbList index.template - fun theme_linktree -->
      
      ';
   if (($jcl_schema!=$jcl_schemaold) || ($jcl_schema==null)) {
      echo $jcl_schema;
      $jcl_schemaold=$jcl_schema;
   }
   //--
   $shown_linktree = true;
}

^SoporteGSM^


Diego Andrés

Es un poco diferente, pero debería de ser adaptable sin mucho esfuerzo.

SMF Tricks - Free & Premium Responsive Themes for SMF.

^SoporteGSM^

Como seria la adaptacion?

function theme_linktree($force_show = false)
{
global $context, $shown_linktree, $scripturl, $txt;

// If linktree is empty, just return - also allow an override.
if (empty($context['linktree']) || (!empty($context['dont_default_linktree']) && !$force_show))
return;
echo '
<div class="navigate_section">
<ul>';

if ($context['user']['is_logged'])
echo '
<li class="unread_links">
<a href="', $scripturl, '?action=unread" title="', $txt['unread_since_visit'], '">', $txt['view_unread_category'], '</a>
<a href="', $scripturl, '?action=unreadreplies" title="', $txt['show_unread_replies'], '">', $txt['unread_replies'], '</a>
</li>';

// Each tree item has a URL and name. Some may have extra_before and extra_after.
foreach ($context['linktree'] as $link_num => $tree)
{
echo '
<li', ($link_num == count($context['linktree']) - 1) ? ' class="last"' : '', '>';

// Don't show a separator for the first one.
// Better here. Always points to the next level when the linktree breaks to a second line.
// Picked a better looking HTML entity, and added support for RTL plus a span for styling.
if ($link_num != 0)
echo '
<span class="dividers">', $context['right_to_left'] ? ' &#9668; ' : ' &#9658; ', '</span>';

// Show something before the link?
if (isset($tree['extra_before']))
echo $tree['extra_before'], ' ';

// Show the link, including a URL if it should have one.
if (isset($tree['url']))
echo '
<a href="' . $tree['url'] . '"><span>' . $tree['name'] . '</span></a>';
else
echo '
<span>' . $tree['name'] . '</span>';

// Show something after the link...?
if (isset($tree['extra_after']))
echo ' ', $tree['extra_after'];

echo '
</li>';
}

echo '
</ul>
</div><!-- .navigate_section -->';

$shown_linktree = true;
}

Advertisement: